Set Anim Instance node causing crashes

I just migrated a project from 4.18 to 4.22 and discovered an easily repeatable crash based on something I had working in 4.18. Whenever I use the Set Anim Instance node to change to a different anim blueprint, UE4 crashes.

I tested this extensively in my game and am positive that this is what’s causing the crash. I tried making a blank actor with two blank anim blueprint in a blank level and simply set up the actor to switch anim instances after a couple seconds and it causes a crash. I even tried creating a new project using the third person template, making a child of the third person character’s anim blueprint and then switching to it on begin play, and it also resulted in a crash.

It strikes me as a bug since I didn’t have this issue in 4.18, though I guess I could just be using the node wrong?

Hi, this definitely appears to be a bug. We’ve run into the same issue upgrading from 4.21 but have been unable to resolve it thus far.

I have been able to repro this crash by simply creating a new Character blueprint, creating two different animation blueprints and switching from one to the other using the SetAnimInstance node.

So, you’re not alone.

Since this issue was a big problem for us we did some further digging and found there was a commit in the master branch about 5 days ago titled “Speculative fix w.r.t. copy pose node”: https://github.com/EpicGames/UnrealEngine/commit/c4ea32533ee98508ab68038488a09b3a12d54cd4

We cherry picked only the code changes from SkeletalMeshComponent.cpp for the moment and merged it into our custom engine build and it did indeed resolve our SetAnimInstance related crashes. Fingers crossed this fix makes it into the next 4.22 build!

Good to know I’m not just shoving a square peg in a round hole. Hopefully we get that fix in the first hotfix.

Im also having this crash as well on calling the same node, needs to be hotfix asap.

Just downloaded the latest hotfix, and the issue still appears to be present.

This problem still not be solved in 4.22.1. still crash when i used this node。

Just gave it a go in 4.22.2 and it’s still an issue.

This is causing crashes for my FirstPersonShooterKit as well.

Did anyone found a workaround for this?

Hello!
I have a working solution for 4.22.x that can be implemented at the project level.

EDIT: If you just want a drop in solution that also works with BP only projects:

[Here’s a plugin I made with the workaround described below][1]



Thanks to this answers page I found the commit referencing a fix.
I looked closely through the code and realized the code path is direct, meaning we can call the same code in a wrapper function, before hand!

I’ve made a gist with the details, and example code over here.
https://gist.github.com/underscorediscovery/46ecaf5cc1ba97f1a7e922f6a77a5705

Short answer with code:

  1. expose a function that implements the HandleExistingParallelEvaluationTask

  2. THEN call SetAnimInstanceClass

    void UTypesAndGlobals::SetAnimInstanceClassFix(USkeletalMeshComponent* SkeletalMesh, UClass* NewClass) {
    // For details: https://gist.github.com/underscorediscovery/46ecaf5cc1ba97f1a7e922f6a77a5705
    // We may be doing parallel evaluation on the current anim instance
    // Calling this here with true will block this init till that thread completes
    // and it is safe to continue
    const bool bBlockOnTask = true; // wait on evaluation task so it is safe to swap the buffers
    const bool bPerformPostAnimEvaluation = true; // Do PostEvaluation so we make sure to swap the buffers back.
    SkeletalMesh->HandleExistingParallelEvaluationTask(bBlockOnTask, bPerformPostAnimEvaluation);
    SkeletalMesh->SetAnimInstanceClass(NewClass);
    }

This bug caught us out and I spent a while trying various solutions (deploying a custom engine build would be prohibitive for us)

This that I tried:

  • FCoreDelegates begin/end frame and various checkpoints to call SetAnimInstanceClass - no luck
  • delay of 0 to move the call to somewhere else in the frame, also no luck
  • various other hacky ideas :stuck_out_tongue:

Hope this helps!

commenting (to notify) - I posted an answer that should help!

commenting (to notify) - I posted an answer that should help!

This bug still not solved in 4.22.3. Can confirm it continues to happen in a blank, empty test project. The crash report appears to be happening on line 1554 of the SkeletalMeshComponent.cpp

So I figured out an alternative. When I don’t want the animation blueprint playing, I use the Pause Anims bool set to false. Then I set it back to true when I want it to tick again. Working so far!

I just discovered an alternative for those that don’t know how to use c++ or git or anything like that. Seems to work well and no need to set the animBP to null

I’ve commented that on the release thread as well, and provided a work around in the accepted answer!

ah cool, yea that makes sense. fwiw the git link doesn’t require git, just hit the Download button and it’ll give you a zip file.

Can confirm this is still a bug in 4.22.3 now. Submitted a bug report to Epic, will post updates if they say anything