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.
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!
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!
expose a function that implements the HandleExistingParallelEvaluationTask
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
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