Availability Analysis of UE5 Virtual Assets

UE5虚拟资产的可用性分析

随着游戏规模和资产精度的提升,以及Nanite等技术的应用,项目工程规模急剧膨胀,达到数百G乃至上T的量级,完整拉取的耗时可能数小时。
而每个人在实际开发中,能够用到的资源只占其中的一小部分,所以怎么样减少工程拉取量级,使工程轻量化是需要优化的问题。
在UE5中,官方推出了虚拟资产(VirtualAssets)机制,与P4结合能够做到这一点。

本篇文章会介绍UE5中虚拟资产的配置流程、资产的虚拟化过程与加载代码分析,以及断网可用性的测试。

注:Virtual Assets只能与P4版本控制结合,不支持Git与SVN。

前言

Virtual Assets是一项资产元信息与数据剥离的方案,可以把传统UE项目中的uasset拆分为uasset+payload的形式,对于无需加载的资产而言,只需要虚拟化后的uasset,它不包含实际的资产BulkData,当实际访问到该资产时,再从Server上把资产的Payload数据拉取下来,从而实现减少拉取的工程规模的目的。

在Epic自己的数据中,虚拟化的数据也非常好(Texture是大头,仅贴图虚拟化后就可以减少总体60%的大小):

开启虚拟化

按照官方文档介绍,VirtualAssets默认处于关闭状态,需要添加下面的配置文件手动开启:

1
2
3
4
5
6
7
8
9
10
11
[Core.ContentVirtualization]
SystemName=Default

[Core.VirtualizationModule]
BackendGraph=VABackendGraph_Example

[VABackendGraph_Example]
PersistentStorageHierarchy=(Entry=SourceControlCache)
CacheStorageHierarchy=(Entry=DDCCache)
SourceControlCache=(Type=p4SourceControl, DepotRoot="...")
DDCCache=(Type=DDCBackend)

需要注意DepotRoot需要指定的是虚拟化文件的存放路径,比如存储在//remote_depot/branches/Project/Content/VirtualAssets/,它可以不放置在Content目录下,也不需要拉取该目录。

虚拟化/提交流程

在进行前面的配置之后进入引擎,连接P4,就可以为资产进行虚拟化了。引擎支持在CheckIn时自动执行虚拟化过程。

在引擎内连接p4:

对资产进行check-in,就会自动执行资产的虚拟化,并提交至P4:


提交完之后,可以在p4上看到提交记录,以及每个hash与资产的对应关系:

Description中的内容是:前6个字符是路径(每两个字符是一级路径),后面的部分是实际的hash值。

在引擎中可以查看Has Virtualized Data来资产是否进行过虚拟化:

在p4中设定的Depot目录下就会新增upayload文件了:

upayload文件的存储方式只按照hash化命名,并没有按照类型、路径之类的进行区分。
举个例子,Texture和StaticMesh的payload只看路径和名字是完全无法区分的:

虚拟化之后,Asset的大小会有明显变化(几MB到10K量级):

除了在Editor内CheckIn之外,引擎还提供了一个工具UnrealVirtualizationTool来批量虚拟化和逆转换。

执行参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
Usage:
Commands:
<ProjectFilePath> -Mode=Virtualize -Changelist=<number> -Submit [optional]
<ProjectFilePath> -Mode=Virtualize -Path=<string>
LogVirtualizationTool: Display:
<ProjectFilePath> -Mode=Rehydrate -Package=<string>
<ProjectFilePath> -Mode=Rehydrate -PackageDir=<string>
<ProjectFilePath> -Mode=Rehydrate -Changelist=<number>
Legacy Commands:
-Mode=Changelist -ClientSpecName=<name> [optional] -Changelist=<number> -nosubmit [optional]
-Mode=PackageList -Path=<string>
Global Options:
-MinimalLogging (demote log messages with 'display' verbosity to 'log' verbosity except those using the LogVirtualizationTool category)

仅虚拟化部分资产

禁用资产类型

如果想要某种类型不参与虚拟化,引擎提供了配置支持。

DefaultEngine.ini中控制某种类型的资产不参与虚拟化:

Developer/Virtualization/Private/VirtualizationManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
TArray<FString> DisabledAssetTypesFromIni;
if (ConfigFile.GetArray(LegacyConfigSection, TEXT("DisabledAsset"), DisabledAssetTypesFromIni) > 0 ||
ConfigFile.GetArray(ConfigSection, TEXT("DisabledAsset"), DisabledAssetTypesFromIni) > 0)
{
UE_LOG(LogVirtualization, Display, TEXT("\tVirtualization is disabled for payloads of the following assets:"));
DisabledAssetTypes.Reserve(DisabledAssetTypesFromIni.Num());
for(const FString& AssetType : DisabledAssetTypesFromIni)
{
UE_LOG(LogVirtualization, Display, TEXT("\t\t%s"), *AssetType);
DisabledAssetTypes.Add(FName(AssetType));
}
}

可以在Core.ContentVirtualizationCore.VirtualizationModule的Section下添加:

1
2
[Core.VirtualizationModule]
+DisabledAsset="Texture2D"

在启动时就会有如下输出:

1
2
LogVirtualization: Display: 	Virtualization is disabled for payloads of the following assets:
LogVirtualization: Display: Texture2D

在引擎内提交贴图时就不会自动进行虚拟化了。

但引擎目前(UE5.6.0)仅提供了DiabledAsset的配置,相当于黑名单。并没有提供类似白名单的选项,这个可以自己改引擎代码扩展。

禁用路径/资产

如果想要某些路径/资产控制是否虚拟化,可以把下面的配置放入DefaultEngine.ini中:

DefaultEngine.ini
1
2
3
[/Script/Virtualization.VirtualizationFilterSettings]  
+ExcludePackagePaths="/Game/Meshs"
+IncludePackagePaths="/Game/Textures"

这两项配置会在FVirtualizationManager::ShouldVirtualizePackage中使用:

注意事项

  1. You cannot mark the Saved/VASubmission directory as p4ignore; if Saved/ is added, it will also be filtered out.
  2. After an asset is virtualized, if the asset within the engine is deleted, the corresponding virtualized file will not be deleted; it will continue to accumulate.
  3. Virtualized files are automatically deduplicated. For example, if the same image is imported multiple times, it will not generate multiple upayload files but will share a single one.
  4. If the network is unavailable or slow, Payload extraction will be slower, affecting VA efficiency.
  5. You can use UnrealVirtualizationTool for batch virtualization and rehydration.

加载虚拟化数据

从DDC获取

When loading an already virtualized asset, it will first try to retrieve it from the DDC:

In UE5, the path for the local DDC is %LOCALAPPDATA%l/UnrealEngine/Common/Zen/Data. To simulate a scenario without local DDC cache, you can delete this directory.

If it can be retrieved from the DDC, the payload on P4 will not be requested.

从p4获取

If the asset’s cache cannot be retrieved from the DDC, it will try to retrieve it from P4:

After retrieving the data, there will be no difference from normal asset access.

无网络访问

When asset virtualization is enabled and there is no cache in the DDC, if network failure occurs and P4 cannot be accessed, the following error will be reported when opening resources:

Either retry the request or exit the engine directly.

Assets loaded passively also follow this logic (e.g., open scene -> load model -> load texture). If the virtualized data for a texture cannot be loaded, it will also prevent the map from opening:

This means that if the network status is poor, Virtual Assets are completely unusable.

The engine internally supports ignoring pop-ups and not exiting the editor via UseLegacyErrorHandling in Core.VirtualizationModule, but this will trigger assertions: non-fatal for textures and fatal for StaticMeshes.

Although it’s possible to open textures without errors, the texture dimensions will be displayed as 0x0:

Note: Regarding the no-network issue, the author also asked Epic officials on UDN. Currently, there are no official development plans for fallback temporary data when offline. Instead, it is recommended to fully download payload data when the network is good.

错误处理

p4 server配置

If the following error is reported during check-in within the engine:

1
2
3
SourceControl: Error: CommandMessage Command: CreateWorkspace, Error: Error in client specification.
'partitioned' client type has not been configured for this server.
Storage location 'client.readonly.dir' needs to be set by the administrator.

This is because Virtual Assets also requires P4 server configuration support, enabling the following two settings:

  • partitioned
  • The virtualized storage directory (DepotRoot) needs to be set to client.readonly.dir.

Then, virtualization can be performed and submitted normally during check-in:

相关资料

Official Documentation

总结

Overall, UE5’s Virtual Assets is a resource management method that can significantly reduce the amount of assets pulled. When the network is stable, the asset access experience is not significantly different from native access.

Virtual Assets should ideally be combined with Shared DDC. Although they are not strongly coupled, it is necessary from an experience perspective. Once the corresponding asset is cached in the DDC, not every user will have to pull the file from the P4 Server; instead, it will be accessed primarily from the DDC, which can greatly alleviate the download pressure on the P4 Server.

Furthermore, virtualization can also achieve asset deduplication. For instance, if the same texture is imported twice, there will actually only be one Payload, which avoids asset storage redundancy (though there will still be two uasset files for the actual assets, but they are relatively small).

Additionally, Virtual Assets can only be combined with P4 and lacks sufficient support for other version control systems. It is unusable in an offline state, so its enablement needs to be evaluated based on actual project circumstances.

My recommendation: If your new UE5 project uses P4 for version control, has good internal network stability, and can deploy Shared DDC, you can enable Virtual Assets.

The article is finished. If you have any questions, please comment and communicate.

Scan the QR code on WeChat and follow me.

Title:Availability Analysis of UE5 Virtual Assets
Author:LIPENGZHA
Publish Date:2025/09/26 17:34
Word Count:5k Words
Link:https://en.imzlp.com/posts/6069/
License: CC BY-NC-SA 4.0
Reprinting of the full article is prohibited.
Your donation will encourage me to keep creating!