Please add UPROPERTY(meta = (BindWidget)) support for UWidgetAnimation!

Still think it’s a bit weird that we haven’t got this.

We can access UWidget children in C++ by declaring a pointer to the related type with UPROPERTY(meta = (BindWidget)) (which also forces the blueprintee to create said child). It would be really beneficial if we could do this with animations too, because otherwise we can’t play animations from C++ directly. Currently, the workaround is to make a pointer with BlueprintReadWrite and then set the pointer in the widget.

Sometimes, this pointer isn’t set early enough too - because the earliest event we have is PreConstruct() (in some cases I need my animations set before this, and created an OnInitialized() event.

Answerhub: https://answers.unrealengine.com/questions/721565/please-add-upropertymeta-bindwidget-support-for-uw.html

I do agree. Another workaround for retrieving the UWidgetAnimation pointer is by iterating through all properties of the UUserWidget in C++ (e.g. using this in NativeConstruct), however NativeContruct() is called often (e.g. when adding this widget to a panel using AddChild) and the method is cumbersome.

Some kind of UPROPERTY(meta = (BindWidgetAnimation)) would be helpful!

Yeah I used to do things like that before I knew BindWidget existed, I’m going to look into adding this myself.

This is obviously far from ideal but this is what I use to get animations:



void UViewWidget::GetAnimations(TMap<FString, UWidgetAnimation*>& OutResults)
{
    OutResults.Empty();

    UProperty* Property = GetClass()->PropertyLink;
    while (Property != nullptr)
    {
        if (Property->GetClass() == UObjectProperty::StaticClass())
        {
            UObjectProperty* ObjectProperty = Cast<UObjectProperty>(Property);

            if (ObjectProperty->PropertyClass == UWidgetAnimation::StaticClass())
            {
                UObject* Object = ObjectProperty->GetObjectPropertyValue_InContainer(this);
                UWidgetAnimation* WidgetAnimation = Cast<UWidgetAnimation>(Object);

                if (WidgetAnimation != nullptr)
                {
                    FString Name = WidgetAnimation->GetMovieScene()->GetFName().ToString();
                    OutResults.Add(Name, WidgetAnimation);
                }
            }
        }

        Property = Property->PropertyLinkNext;
    }
}



@TheJamsh I’ve implemented this feature in my engine source. I’ll make a pull request as soon as I can.

The meta specifiers are BindAnimation and BindAnimationOptional.

Cheers!

Edit: https://github.com/EpicGames/UnrealEngine/pull/4930

Cheers!

2 Likes

well to do animations this will work right ??

1 Like