Skip to content

Instantly share code, notes, and snippets.

Embed
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: https://answers.unrealengine.com/questions/887556/view.html
// This post references a key commit here: https://github.com/EpicGames/UnrealEngine/commit/c4ea32533ee98508ab68038488a09b3a12d54cd4#diff-73715a20583ca5ead5c94c9183679d47
// 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: 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);
}
//Header configuration for clarity and descriptive purposes:
UCLASS()
class MYPROJECT_API UTypesAndGlobals : public UBlueprintFunctionLibrary {
GENERATED_BODY()
public:
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.