Download

Initialization Order of Animation is garbage

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:


And here is a Screenshot of APawn

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.

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.

Its the AnimBlueprints “Update Animation” event.

Unbenannt.jpg

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.

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.

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.

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.

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.

Interesting. What a mess.