Actor的生命周期图


Load from Disk

This path occurs for any Actor that is already in the level, like when LoadMap occurs, or AddToWorld (from streaming or sub levels) is called.

  1. Actors in a package/level are loaded from disk.

  2. PostLoad - is called by serialized Actor after they have finished loading from disk. Any custom versioning and fixup behavior should go here. PostLoad is mutually exclusive with PostActorCreated.

  3. InitializeActorsForPlay

  4. RouteActorInitialize for any non-initialized Actors (covers seamless travel carry over)

    1. PreInitializeComponents - Called before InitializeComponent is called on the Actor's components

    2. InitializeComponent - Helper function for the creation of each component defined on the Actor

    3. PostInitializeComponents - Called after the Actor's components have been initialized

  5. BeginPlay - Called when the level is started

Play in Editor

The Play in Editor path is mostly the same as Load from Disk, however the Actors are never loaded from disk, they are copied from the Editor.

  1. Actors in the Editor are duplicated into a new World

  2. PostDuplicate is called

  3. InitializeActorsForPlay

  4. RouteActorInitialize for any non-initialized Actors (covers seamless travel carry over)

    1. PreInitializeComponents - Called before InitializeComponent is called on the Actor's components

    2. InitializeComponent - Helper function for the creation of each component defined on the Actor

    3. PostInitializeComponents - Called after the Actor's components have been initialized

  5. BeginPlay - Called when the level is started

Spawning

When spawning (instancing) an Actor, this is the path that will be followed.

  1. SpawnActor called

  2. PostSpawnInitialize

  3. PostActorCreated - called for spawned Actors after its creation, constructor like behavior should go here. PostActorCreated is mutually exclusive with PostLoad.

  4. ExecuteConstruction:

    • OnConstruction - The construction of the Actor, this is where Blueprint Actors have their components created and blueprint variables are initialized

  5. PostActorConstruction:

    1. PreInitializeComponents - Called before InitializeComponent is called on the Actor's components

    2. InitializeComponent - Helper function for the creation of each component defined on the Actor

    3. PostInitializeComponents - Called after the Actor's components have been initialized

  6. OnActorSpawned broadcast on UWorld

  7. BeginPlay is called.

Deferred Spawn

An Actor can be Deferred Spawned by having any properties set to "Expose on Spawn."

  1. SpawnActorDeferred - meant to spawn procedural Actors, allows additional setup before Blueprint construction script

  2. Everything in SpawnActor occurs, but after PostActorCreated the following occurs:

    1. Do setup / call various "initialization functions" with a valid but incomplete Actor instance

    2. FinishSpawningActor - called to Finalize the Actor, picks up at ExecuteConstruction in the Spawn Actor line.

Coming to the End of Life

Actors can be destroyed in a number of ways, but the way they end their existence is always the same.

During Gameplay

These are completely optional, as many Actors will not actually die during play.

Destroy - is called manually by game any time an Actor is meant to be removed, but gameplay is still occurring. The Actor is marked pending kill and removed from Level's array of Actors.

EndPlay - Called in several places to guarantee the life of the Actor is coming to an end. During play, Destroy will fire this, as well Level Transitions, and if a streaming level containing the Actor is unloaded. All the places EndPlay is called from:

  • Explicit call to Destroy

  • Play in Editor Ended

  • Level Transition (seamless travel or load map)

  • A streaming level containing the Actor is unloaded

  • The lifetime of the Actor has expired

  • Application shut down (All Actors are Destroyed)

Regardless of how this happens, the Actor will be marked RF_PendingKill so during the next garbage collection cycle it will be deallocated. Also, rather than checking for pending kill manually, consider using an FWeakObjectPtr as it is cleaner.

OnDestroy - This is a legacy response to Destroy. You should probably move anything here to EndPlay as it is called by level transition and other game cleanup functions.

Garbage Collection

Some time after an Actor has been marked for destruction, Garbage Collection will occur to actually remove the Actor from memory, freeing any resources it was using.

  1. BeginDestroy - This is the Actor's chance to free up memory and handle other multithreaded resources (ie: graphics thread proxy objects).

  2. IsReadyForFinishDestroy - This lets the garbage collection know when it is ready to be deallocated permanently.

  3. FinishDestroy - Finally, the Actor is really going to be destroyed, and this is another chance to free up internal data structures. This is the last call before memory is freed.


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值