PlayAnimation doesn't work in edit mode

I would expect this to work: (It does not)

USkeletalMeshComponent* meshcomp = GetMesh();
UAnimationAsset* anim = loadAnimation(anipath); // calls LoadObject<UAnimationAsset>
meshcomp->PlayAnimation(anim, true);

This code is implemented in a derived ACharacter and called on first tick.
Ticking in edit mode has been enabled by overriding ShouldTickIfViewportsOnly()

Hey rotwang-

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).

USkeletalMeshComponent* meshcomp = GetMesh();
AnimAsset = LoadObject<UAnimationAsset>(NULL, TEXT("AnimSequence'/Game/Mannequin/Animations/ThirdPerson_Jump.ThirdPerson_Jump'B"));
meshcomp->PlayAnimation(AnimAsset, true);

I was also able to use a constructor helper to get the animation asset and then call PlayAnimation on begin play.

static ConstructorHelpers::FObjectFinder<UAnimationAsset> anim(TEXT("AnimSequence'/Game/Mannequin/Animations/ThirdPerson_Jump.ThirdPerson_Jump'B"));
if (anim.Succeeded())
{
	AnimAsset = anim.Object;
}

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.

Cheers

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.

   void USkeletalMeshComponent::PlayAnimation(class UAnimationAsset* NewAnimToPlay, bool bLooping)
    {
    	SetAnimationMode(EAnimationMode::AnimationSingleNode);
    	SetAnimation(NewAnimToPlay);
    	Play(bLooping);
    }

So what else is needed in Edit mode?
Best, Frank

oooh, than it’s per design and not a bug?
But I’m wondering why this feature is excluded.
Thank you for your help, .