Play animation montage (C++)

I’m trying to set up weapon animations purely in C++. However, calling Montage_play does nothing. If I set up a mostly-blank animation blueprint that only includes the idle animation, or if I select ‘Use Animation Asset’ for Animation Mode on the first person mesh, the mesh will only play that idle animation and nothing else.

This code is almost entirely taken from ShooterGame:

	float animTime = 0.1f;		//Default value in case the animation can't be played.

	// try and play a firing animation if specified
	if (FireAnimation != NULL && playerViewMesh != NULL)
		// Get the animation object for the arms mesh
		UAnimInstance* AnimInstance = playerViewMesh->GetAnimInstance();
		if (AnimInstance != NULL)
			animTime = AnimInstance->Montage_Play(FireAnimation, 1.f);
			if (animTime < 0.1f)
				//The function returns 0 if the animation can't be played.
				animTime = 0.1f;

If the animation blueprint is set or if I’m using the asset, then Montage_play() returns successfully, with a time that is equal to the length of the animation according to the animation viewer. However, as I mentioned, nothing actually plays. The weapon model is locked in the idle animation.

If the blueprint is not set, then GetAnimInstance() returns NULL, which makes it impossible to play the animation.

Is there some setup I’m missing to be able to play animations from C++?

Thank you.

I got it to work. I needed to create a new slot, name it ‘FullBody’, assign all of the montages to use that slot, then add it to the blueprint in a blend node.

I have no idea how much of that is necessary, as I have absolutely no idea why it worked at all. But if someone else has a similar problem, doing that is a good place to start.

i had this same problem but aim using mix of cpp and blueprint My problem was same with montage not blending through reload animation I found a different solution to make it work but that what i like about programming you can have multiple solution to problem all working lol, though its time taking.