It's often pretty useful to be able to access UMG-created animations from C++. Especially as you move more and more logic from Blueprints into C++, UMG animations can seem like the last hold-out.
UPDATE: The method I described in an old version of this tutorial is now
not needed! There is now a
meta property that does all the work for us!
BindWidgetOptional are undocumented
meta properties that
we can use to access our animations from C++.
Add variables to the header of your Blueprint's parent C++ class, as shown in the code below.
This works in very much the same way as the
BindWidget meta property that we can use to hook up
C++ to Blueprint widgets.
As of Unreal Engine 5.0 you must mark your properties as
NOTE: This method is deprecated, you just need to do the
method above instead!
With a custom subclass of
UUserWidget, we can create a map of
UWidgetAnimation* and access the animations by name from C++.
Let's see how to do this:
PlayAnimationByNameisn't entirely needed, but it can be a helpful wrapper for the regular