UE5.5通过FWorldPartitionActorDescInstance加载Actor
-
UE5.5目前使用
FWorldPartitionActorDescInstance
来管理world partition下的actor信息和逻辑操作,原来的FWorldPartitionActorDesc
仅储存数据 -
FWorldPartitionActorDescInstance::GetActor
函数不会触发加载,仅用于获取已加载或处于异步加载状态的actor,但如果actor处于异步加载状态时,会触发FWorldPartitionActorDescInstance::FlushAsyncLoad
等待加载完成 -
UE5.5删除了
FWorldPartitionActorDescInstance::Load
接口并将FWorldPartitionActorDesc::Load
设为空函数,仅在private内提供了异步加载接口,理由如下- World Partition Actor Descriptors:
- Make loading functions private to make sure all code requesting actors loading state changes in the editor goes through the loading contexts.
- Actor descriptors can now load async when using the deferred context, in preparation of editor async loading through a new async context.
-
因此外部无法直接通过FWorldPartitionActorDescInstance加载Actor,目前UE提供了两种加载接口
FWorldPartitionLoadingContext::FImmediate
和FWorldPartitionLoadingContext::FDeferred
,分别代表同步和异步加载 -
UE5.5可通过
void FWorldPartitionLoadingContext::LoadAndRegisterActor(FWorldPartitionActorDescInstance* InActorDescInstance)
直接加载actor,其实现如下-
void FWorldPartitionLoadingContext::LoadAndRegisterActor(FWorldPartitionActorDescInstance* InActorDescInstance) { check(!InActorDescInstance->bIsRegisteringOrUnregistering); InActorDescInstance->bIsRegisteringOrUnregistering = true; ActiveContext->RegisterActor(InActorDescInstance); }
-
其中默认情况下,采用同步加载:
-
FWorldPartitionLoadingContext::FImmediate FWorldPartitionLoadingContext::DefaultContext; FWorldPartitionLoadingContext::IContext* FWorldPartitionLoadingContext::ActiveContext = &DefaultContext;
-
-
UE在此基础上封装了类型
typedef TWorldPartitionHandle<FWorldPartitionReferenceImpl> FWorldPartitionReference;
,用于记录actor引用计数,并且可以根据引用计数加载和卸载actor-
/** * FWorldPartitionReference will increment/decrement the hard reference count on the actor descriptor. * This will trigger actor loading/unloading when the hard reference counts gets to one/zero. */
-
-
同时UE还提供了
typedef TWorldPartitionHandle<FWorldPartitionHandleImpl> FWorldPartitionHandle;
类型仅用于记录引用计数-
/** * FWorldPartitionHandle will increment/decrement the soft reference count on the actor descriptor. * This won't trigger any loading, but will prevent cleanup of the actor descriptor when destroying an * actor in the editor. */ typedef TWorldPartitionHandle
FWorldPartitionHandle;
-
-
因此可以通过
FWorldPartitionReference ActorReference(WorldPartition, ActorDesc->GetGuid());
来加载actor,在其构造函数中会记录引用计数,并触发加载任务,其内部也是调用FWorldPartitionLoadingContext::LoadAndRegisterActor
实现的
来一发吐槽