Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SetAnimInstanceClass is broken in unreal 4.22. This is a project-level fix for it till 4.22.3 (or 4.23) comes out.
// Context:
// This post references a key commit here:
// This change forces evaluation to complete, before updating the animation class.
// This happens during ClearAnimScriptInstance - BUT - the code path to this change, is not special.
// That means it should be valid to do this BEFORE calling clear, i.e before even calling SetAnimInstanceClass itself!
// So that's what we do. We simply wrap SetAnimInstanceClass in a function we can call,
// and inside that function we ensure evaluation is complete. This fixes it for me in all my use cases!
// Requires:
// - C++ in your project.
// I used a static global blueprint function library.
// You can put this function *anywhere* that works for you.
//This is the cpp file implementation:
void UTypesAndGlobals::SetAnimInstanceClassFix(USkeletalMeshComponent* SkeletalMesh, UClass* NewClass) {
// For details:
// 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);
//Header configuration for clarity and descriptive purposes:
class MYPROJECT_API UTypesAndGlobals : public UBlueprintFunctionLibrary {
UFUNCTION(BlueprintCallable, Category = "MyProject|4.22 AnimBP fix")
static void SetAnimInstanceClassFix(USkeletalMeshComponent* SkeletalMesh, UClass* NewClass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.