x

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"

AnimMontage Playing... Sort of.

Hello Community,

It's been a while since my last question. So here I am again... oh boy. Anyways...

The Issue The issue I am having is I have created an animation montage for my model. In the editor I can see it working just fine. However, I want to be able to call these on demand via code and it's causing abit of a problem. I've tested to make sure that it is infact running the montage but when looking at the character it's simply "stuck" is the best way I can put it.

A few ideas

I suspect that it's either repeating over and over and over and over again (Even when I turn off the loop it is still going!) so I am pretty sure this is the issue. So the question is how do I fix this? If I want to play it one single time or loop continually while say, running, then what exactly would be the best solution for this? Thanks.

 InputComponent->BindAction("Jump", IE_Pressed, this, &AThePlanetCharacter::Jump);
 
 // ...
 
 void AThePlanetCharacter::Jump()
 {
     ACharacter::Jump();
 
     stuff = GetMesh();
 
 
     if (stuff->AnimScriptInstance->Montage_IsPlaying(Mon) == false)
     {
         stuff->AnimScriptInstance->Montage_Play(Mon, 1.0);
         GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Red, FString::FString("I am definitely on!"));
     }
 
 }

Product Version: Not Selected
Tags:
more ▼

asked Jan 07 '15 at 05:01 AM in C++ Programming

avatar image

Mark James G
514 44 24 51

avatar image Mark James G Jan 08 '15 at 10:12 PM

Update:

I've tried a few different things from UpdateAnimation(1.0) to simply the arrangement of the code. Still nothing yet. Any help would be appreciated. :)

avatar image Mark James G Jan 10 '15 at 07:49 PM

Another new update. I've tried the following from The Shooter Game Example and still nothing. Any assistance would be appreciated.

 float AThePlanetCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
 {
 
     GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Yellow, FString::FString("I am in Anim Montage!"));
 
     USkeletalMeshComponent* UseMesh = GetMesh();
     if (AnimMontage && UseMesh && UseMesh->AnimScriptInstance)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Yellow, FString::FString("I am returning the anim montage!"));
         return UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
     }
 
     return 0.0f;
 }
 
 
 void AThePlanetCharacter::Jump()
 {
     ACharacter::Jump();
 
     float DeathAnimDuration = PlayAnimMontage(Mon);
 
     GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString::SanitizeFloat(DeathAnimDuration) + FString::FString(" Death Anim Duration"));
 
 }
(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Ah, well... I finally figured it out after a few days of experimenting around. Turns out the montage needed a few settings checked in the actual montage. For instance the actual animation references start and end time. alt text

So anyways, the following code works perfectly. Now to blend 'em and to sync. Basically, if you plan on doing it via C++ then you'll want to make sure that you follow this. Then do what you need to do via various functions and timers. Hopefully this helps you guys. It definitely helped me. :)

 float AThePlanetCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
 {
 
     GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Yellow, FString::FString("I am in Anim Montage!"));
 
     USkeletalMeshComponent* UseMesh = GetMesh();
     if (AnimMontage && UseMesh && UseMesh->AnimScriptInstance)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Yellow, FString::FString("I am returning the anim montage!"));
         return UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
     }
 
     return 0.0f;
 }
 
 
 void AThePlanetCharacter::Jump()
 {
     ACharacter::Jump();
 
     float DeathAnimDuration = PlayAnimMontage(Mon);
 
     GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, FString::SanitizeFloat(DeathAnimDuration) + FString::FString(" Death Anim Duration"));
 
 
 }

alt text

answer1.png (12.7 kB)
answer2.png (24.8 kB)
more ▼

answered Jan 10 '15 at 08:22 PM

avatar image

Mark James G
514 44 24 51

(comments are locked)
10|2000 characters needed characters left
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