Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can't play animation from C++


My team created some Anim sequences, and converted them to Anim montages, so it would be played from code.

The code

 bool AMyCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
     USkeletalMeshComponent* UseMesh = GetPawnMesh();
     if (AnimMontage && UseMesh && UseMesh->AnimScriptInstance)
         return (UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate) > 0 ? true: false);
     return false;

The mesh matches the Animations, and everything plays out smoothly in the editor, but I can't for the life of me get the animations to activate from code.

Is there anything I might have missed??

Product Version: Not Selected
more ▼

asked Mar 11 '14 at 02:27 AM in C++ Programming

avatar image

ue4-archive ♦♦ STAFF
50.1k 3672 2002 9129

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Dear Abdullah,

Several things to check:

-Do you have a FullBody slot in your animation Blueprint for your character

alt text

-Did you make sure to type in the name of your slot such as FullBody into every montage that you are calling?

alt text

-Are you sure that your montage references are not null?

Post your code for how you are referencing your montages in your code if you are not sure about this part

 if(!MyMontageRef) //log = this montage is NULL!

If this answers your question please add a comment to explain what part was the solution for you and mark the check by my answer so others know it has been resolved. This will help with ppl searching the UDN in the future.

fullbody.jpg (56.2 kB)
montage editor.jpg (238.8 kB)
more ▼

answered Mar 11 '14 at 02:27 AM

avatar image

ue4-archive ♦♦ STAFF
50.1k 3672 2002 9129

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:27 AM

Hey Rama I created a FullBody slot, linked it to the montages, and checked the referencing. Everything is solid, but it is still not working.

I even checked the return of this function:

     return (UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate) > 0 ? true: false);

and it returned true. Even the name of the AnimMontage was correct. I reference the montages from the editor

     struct FComboMontages
         UPROPERTY(EditDefaultsOnly, Category=Animation)
         UAnimMontage* LightSlash;
         UPROPERTY(EditDefaultsOnly, Category=Animation)
         UAnimMontage* HeavySlash;
     //Inside Character.h class declaration
     UPROPERTY(EditAnywhere, Category=Sword)
     FComboMontages MyComboMontages;

Also a couple of screenshots for further clarification alt text

alt text

untitled.png (75.8 kB)
untitle2d.png (17.0 kB)
avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:27 AM

well I am not in any way trying to sound demeaning, but are you sure that your character is using the latest version of your animation blueprint that you showed a picture of? could you confirm this by using a different default animation sequence besides the jump one?

Because everything you are describing sounds great to me.

The only other thing you could consider checking,

your struct is EditAnywhere but the contents are edit defaults only

could you just, for my sake anyway,

just reference the montages directly in your character.h like this:

this is how I do it:

 class AJoyWarriorBase : public AVictoryPlayerCharacterBase, public IVictoryVibesInterface
     //~~~ Swing Montages! ~~~
     UPROPERTY(EditDefaultsOnly, Category=JoyAnims)
     UAnimMontage* Swing1;

Again this is all just for debugging purposes, I am not saying anything is wrong with your setup, I'm just trying to get more data by trying different things



avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:27 AM

Just changed the character.h file to reference the montages directly just like your setup, but with no luck.

I did try four different montages, and none of them worked. I think the problem maybe in the animation blueprint because I checked the codes a thousand times and I really can't find anything wrong with it.

Really appreciate the help, man

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:27 AM

Are you sure that, in your character blueprint, you have your current animation blueprint listed?

and did you try changing that default animation to something else to confirm you are working with the latest version of the anim BP ?

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:27 AM +

You got it.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question