This code is implemented in a derived ACharacter and called on first tick.
Ticking in edit mode has been enabled by overriding ShouldTickIfViewportsOnly()
There are a couple of questions I have about this code. What is “anipath”? What exactly does loadAnimation() do? I ask because, using a third person template project, this code compiles and works to play the set animation (this was done in the BeginPlay() function).
Hey ,
yes, your code is similar to mine , anipath is just a TEXT path to the asset.
My code also is working fine as soon as I’m in PLAY mode, eg calling it in the BeginPlay() function.
The actual problem is, that it will not play the animation in EDIT mode, even if I enable ShouldTickIfViewportsOnly()
When you say edit mode, are you referring to inside the blueprint? If that is the case, the reason assigning the animation isn’t causing it to play is that AnimScriptInstance isn’t set. PlayAnimation calls SetAnimation which assigns a UAnimSingleNodeInstance pointer based on the returned value of GetSingleNodeInstance().
Within the blueprint editor, with a skeletal mesh component selected, if the Animation Mode is set to “Use Animation Asset”, I’ve found that GetSingleNodeInstance() returns true (AnimScriptInstance is set) when the “Anim to Play” dropdown is clicked. This is why when setting an animation with this dropdown it will automatically begin to play/loop. If you are trying to see an animation play in the blueprint, there are animation options that already exist for the skeletal mesh component.
If you are trying to get the animation to play while in the viewport of the editor, you would have to edit engine level code to make the animation behavior mimic what happens inside of blueprints. I understand that you’re not using blueprints. However, even when an animation is set and plays in a blueprint, the animation does not play when an instance of the blueprint is added to the viewport until Play is pressed.
,
no blueprint here. All pure C++, code implemented in a class derived from ACharacter.
Edit mode means the status in Editor, where we edit the level before hitting play.
The class is ticked correctly, but the animation won’t play.
The animation plays only after clicking Play.
As you wrote, the engine’s implementation of PlayAnimation sets SingleNode mode automatically.