Linker error using UWidgetAnimation::BindToAnimationFinished

Hi,

I’m really bugged by a LNK2019 happening trying to use UWidgetAnimation::BindToAnimationFinished.

I do have the UMG modules specified in my Build.cs:


public class Theseus : ModuleRules
{
public Theseus(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
PublicDependencyModuleNames.AddRange(new string] { "UMG", "Slate", "SlateCore" });
PrivateDependencyModuleNames.AddRange(new string] { "GameplayTasks", "AIModule", "NavigationSystem" });
PrivateDependencyModuleNames.AddRange(new string] { "Niagara" });
}
}


I do have the right includes in my widget class (derived from UUserWidget):


#include "Animation/WidgetAnimation.h"
#include "Blueprint/UserWidget.h"

And this is how I’m trying to bind a UFUNCTION with BindToAnimationFinished:


FWidgetAnimationDynamicEvent MyAnimationEvent;
MyAnimationEvent.BindDynamic(this, &UWidgetInventory::BindingTest);
GetAnimationByName(TEXT("FadeOutMessages"))->BindToAnimationFinished(this, MyAnimationEvent);

However, no matter how I clean my build and rebuild, this is what I get:


error LNK2019: unresolved external symbol "public: void __cdecl UWidgetAnimation::BindToAnimationFinished(class UUserWidget *,class FWidgetAnimationDynamicEvent)" (?BindToAnimationFinished@UWidgetAnimation@@QEAAXPEAVUUserWidget@@VFWidgetAnimationDynamicEvent@@@Z) referenced in function "protected: virtual void __cdecl UWidgetInventory::NativeConstruct(void)" (?NativeConstruct@UWidgetInventory@@MEAAXXZ)


I’ve also tried to use a plain pointer to a specified UWidgetAnimation (ie. not a pointer returned by my function GetAnimationByName) to no avail.

I beg your help, this is driving me crazy!

Thank you,

f

Nobody? Maybe @Sveitar can help, looks like he was investigating the same issue when BindToAnimationFinished was introduced in 4.22?

https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1602389-c-transition-guide-for-4-22?p=1602742#post1602742

I have no idea to be honest. I’ve checked the source code, this BindToAnimationFinished function basically calls the same function on the given widget, so maybe you could try binding on the widget itself rather then the widget animation?



// From UE source code
void UWidgetAnimation::BindToAnimationFinished(UUserWidget* Widget, FWidgetAnimationDynamicEvent Delegate)
{
     if (ensure(Widget))
     {
          // Call this directly on your widget rather then through this function?
          Widget->BindToAnimationFinished(this, Delegate);
     }
}


I am successfully using this code in 4.25



// .h
class UBackgroundImageWidget : public UUserWidget

...

UPROPERTY(*meta *= (*BindWidgetAnim*))
UWidgetAnimation* **SwitchImageAnim**;

...

UFUNCTION()
void OnBackgroundImageTransitionFinished();

// .cpp
void UBackgroundImageWidget::NativeConstruct()
{
     Super::NativeConstruct();
     check(**SwitchImageAnim**);
     FWidgetAnimationDynamicEvent AnimationEvent;
     AnimationEvent.BindDynamic(this, &UBackgroundImageWidget::OnBackgroundImageTransitionFinished);
     BindToAnimationFinished(**SwitchImageAnim**, AnimationEvent);
}

void UBackgroundImageWidget::OnBackgroundImageTransitionFinished()
{
    ...
}


@Neyl_S THANKS A TON! Your solution does indeed work: BindToAnimationFinished simply needs to take the animation you want to bind your event to as its first argument. That’s just all but obvious from the function signature (am I the only one dreaming about the day when the online Unreal Engine API Reference will actually provide examples of functions usage? :)).

cheers

f

1 Like

Another example of the code.working.

.h
public:
	UPROPERTY(BlueprintReadWrite)//call from editor
	UWidgetAnimation* ref_animation_buton_info{ nullptr };//get animation from C++

	FWidgetAnimationDynamicEvent to_end_animation_button_info_delegate; //delegate to function

	UFUNCTION()
	void to_end_animation_button_info();//function
.cpp
void UMenuInitWiget::NativeConstruct()
{
	Super::NativeConstruct();
	 	to_end_animation_button_info_delegate.BindDynamic(this,&UMenuInitWiget::to_end_animation_button_info);
	
if (ref_animation_buton_info == nullptr) return;
BindToAnimationFinished(ref_animation_buton_info,to_end_animation_button_info_delegate);


}

void UMenuInitWiget::to_end_animation_button_info()
{
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Yellow, TEXT("hello end animation"));
	
}

Blueprint pre construct set animation