# Initialization Order of Animation is garbage

**URL:** <https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639>\
**Category:** Feedback & Requests\
**Tags:** unreal-engine\
**Created:** [April 7, 2019, 6:59pm UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639 "2019-04-07T18:59:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [April 7, 2019, 6:59pm UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/1 "2019-04-07T18:59:03Z")

</div>

Skeletal Mesh Components are a hell to work with if you want to bind Delegates and such before the animation initializes.  
Because no matter what you do, the Animation is initialized AND TICKS before PostInitializeComponents is called (The Function of choice when you want to interconnect Components, similar to Unity’s “Awake()”)  
And if that’s not enough, it also differs between ACharacter and APawn (SkeletalMeshComponent is added via Blueprint Editor)  
Here is a Screenshot of ACharacter derived:

 ![Character.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/a/eab108c887e11c40f022cf66440778b7b71f986e.jpeg)  
And here is a Screenshot of APawn  
 ![Pawn.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/1/51bdae82589ac9325821de37047877c161f70bc4.jpeg)

In the latter case it’s even more confusing, since the Animation is even UPDATED before the SkeletalMesh is even Activated  
~~Valve~~ Epic, pls fix.

---

<div class="post-metadata">

**Author:** ![DamirH](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damirh/32/906591_2.png) [@DamirH](https://forums.unrealengine.com/u/DamirH)\
**Post date:** [April 7, 2019, 11:47pm UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/2 "2019-04-07T23:47:14Z")

</div>

The UpdateAnimation call, is that the animation blueprint’s “tick” function, or a code override?

Edit: Also, where does PreInitializeComponents fall into the stack? Anything stopping you from using that? Binding to delegates should be safe in there too.

---

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [April 8, 2019, 4:46am UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/3 "2019-04-08T04:46:00Z")

</div>

> [@DamirH](#):
>
> The UpdateAnimation call, is that the animation blueprint’s “tick” function, or a code override?

Its the AnimBlueprints “Update Animation” event.

> [@DamirH](#):
>
> Edit: Also, where does PreInitializeComponents fall into the stack? Anything stopping you from using that? Binding to delegates should be safe in there too.

![Unbenannt.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/8/b8c11c13b919df8d6af73e6701ce3064b9d17786.jpeg)

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [April 8, 2019, 8:03am UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/4 "2019-04-08T08:03:34Z")

</div>

Animations are ticked once when InitAnim() in the Skeletal Mesh is called - I suspect this is because otherwise there will be a frame or two where the mesh will appear in it’s default pose, since anims are usually updated on another thread.

The Skeletal Mesh Component calls InitAnim when the component is registered via OnRegister() - where it manually ticks the animation with zero delta time. OnRegister() is called before any kind of component initialization.

> **[Actor Lifecycle](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Actors/ActorLifecycle/)**
>
> What actually happens when an Actor is loaded or spawned, and eventually dies.

I suspect it differs in ACharacter because characters regularly change the “bOnlyAllowAutonomousTickPose” value so that animation properly links up with networked movement - otherwise the animation would be ticking in between updates which you don’t want.

---

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [April 8, 2019, 9:21am UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/5 "2019-04-08T09:21:46Z")

</div>

But thats insane. Update Animation is accessing components (cached or non-cached). These components are not there before PostInitializeComponents, causing lots of Null References.  
You would need to make a Branch “IsInitialized” in UpdateAnimation to forbid the Access on Null Components.  
I already had this problem in the past. To me it looks like there is absolutely NO solution for this.

---

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [April 8, 2019, 5:07pm UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/6 "2019-04-08T17:07:16Z")

</div>

Okay, so I have a workaround for this.

You simply set the Animation Instance to Null in the constructor and set the correct AnimInstance (AnimationBlueprint) on the Instance via Blueprint/World Outliner where you want it (in my case, in PostInitializeComponent)  
It’s hacky, but it works and I would like to see a better initialization order in the future.

 ![Unbenannt.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/a/8aaf1019e4c0178fefb45b5a9f58205ff04a0567.jpeg)

---

<div class="post-metadata">

**Author:** ![DamirH](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/damirh/32/906591_2.png) [@DamirH](https://forums.unrealengine.com/u/DamirH)\
**Post date:** [April 8, 2019, 10:22pm UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/7 "2019-04-08T22:22:43Z")

</div>

I think the “by the books” solution to this is to have your custom UAnimInstance subclass and inject whatever you need into that class’ OnRegister() function.

---

<div class="post-metadata">

**Author:** ![Raildex](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raildex](https://forums.unrealengine.com/u/Raildex)\
**Post date:** [April 9, 2019, 7:51am UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/8 "2019-04-09T07:51:53Z")

</div>

> [@DamirH](#):
>
> I think the “by the books” solution to this is to have your custom UAnimInstance subclass and inject whatever you need into that class’ OnRegister() function.

that would mean fiddle around in USkeletalMeshComponent’s OnRegister / InitAnim function. That doesnt sound well either.  
It also gets Initialized multiple Times.  
OnRegister and InitializeComponent.

---

<div class="post-metadata">

**Author:** ![wilberolive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wilberolive](https://forums.unrealengine.com/u/wilberolive)\
**Post date:** [June 15, 2019, 1:31am UTC](https://forums.unrealengine.com/t/initialization-order-of-animation-is-garbage/124639/9 "2019-06-15T01:31:03Z")

</div>

Interesting. What a mess.
