Description

After compiling the Animation Blueprint (ABP) during Play In Editor (PIE), the callback registered with UAnimInstance::AddNativeStateEntryBinding() in NativeInitializeAnimation() stops functioning as expected. Specifically, the callback is called expectedly before the compilation, but after recompiling the ABP during the PIE session, the callback is no longer triggered.

Workaround: Restart PIE whenever ABP is compiled.

Steps to Reproduce
  1. Create a new project by the third person template with C++ option
  2. Navigate Tools > New Class, in order to add a new C++ class, "MyAnimInstance", inheriting AnimInstance class.
  3. Add overrides for NativeInitializedAnimation() and OnEnterAnyAnimationState(), referring to the code snippet shown below this list of steps.
  4. Open ABP_Manny and change Parent Class to MyAnimInstance in Class Settings.
    Restart the editor.
  5. Dock the Output Log panel and run PIE.
  6. Confirm "Log OnEnteredAnyAnimationState Walk / Run -> Idle" is logged after moving the character.
  7. Compile ABP_Manny during this PIE session.
  8. Confirm "Log OnEnteredAnyAnimationState Walk / Run -> Idle" is no longer being output after moving the character.

Expected Result: "Log OnEnteredAnyAnimationState Walk / Run -> Idle" appears in the log when you move the character and stop it. It means the callback should continue to function correctly after recompiling the ABP during PIE.

Actual Result: That log is not output to log anymore. The callback stops functioning (= not being called)  after the ABP is recompiled during PIE.

Code Snipet: (* The repro project is available and attached)

MyAnimInstance.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Animation/AnimInstance.h"
#include "MyAnimInstance.generated.h"

/**
 * 
 */
UCLASS()
class TPCPP54_ISSUE_API UMyAnimInstance : public UAnimInstance
{
	GENERATED_BODY()
	
public:
	void NativeInitializeAnimation() override;

	void OnEnterAnyAnimationState(const struct FAnimNode_StateMachine& machine, int32 prevStateIndex, int32 nextStateIndex);
};

 
MyAnimInstance.cpp

#include "MyAnimInstance.h"
#include <Animation/AnimNode_StateMachine.h>

void UMyAnimInstance::NativeInitializeAnimation()
{
	Super::NativeInitializeAnimation();

	UE_LOG(LogTemp, Log, TEXT("Log NativeInitializeAnimation Owner:%s"), *GetNameSafe(GetOwningActor()));

	AddNativeStateEntryBinding(TEXT("Locomotion"), TEXT("Idle"), FOnGraphStateChanged::CreateUObject(this, &ThisClass::OnEnterAnyAnimationState));
}

void UMyAnimInstance::OnEnterAnyAnimationState(const struct FAnimNode_StateMachine& machine, int32 prevStateIndex, int32 nextStateIndex)
{
	UE_LOG(LogTemp, Log, TEXT("Log OnEnteredAnyAnimationState %s -> %s"), *machine.GetStateInfo(prevStateIndex).StateName.ToString(), *machine.GetStateInfo(nextStateIndex).StateName.ToString());
}

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-221858 in the post.

0
Login to Vote

Unresolved
ComponentUE - Anim - Runtime - Anim Blueprints
Affects Versions5.4.3
Target Fix5.6
CreatedAug 15, 2024
UpdatedSep 26, 2024
View Jira Issue