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"

Play Montage in c++ with OnBlendOut, OnInterrupted, etc...

How do I play an animation montage on a skeletal mesh component from c++ such that I can get callbacks for OnCompleted, OnBlendOut, OnInterrupted, etc... just like the "PlayMontage" node in the picture?

I found this function but I don't see any way to bind callbacks to it:

 ![BirdSkeletalMesh->GetAnimInstance()->Montage_Play(...);][1]

Thanks in advance for your help!

[1]: /storage/temp/274078-blueprint.png

Product Version: UE 4.22
Tags:
blueprint.png (46.1 kB)
more ▼

asked Apr 13 '19 at 06:30 PM in C++ Programming

avatar image

Blindopoly
5 1 1

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

1 answer: sort voted first

You can look into the UPlayMOntageCallbackProxy how it's done in the engine.

But what basically happens is, The montage is started with AnimInstance->Montage_Play and if that is successful you set right callbacks on the animinstance:

AnimInstance->Montage_SetBlendingOutDelegate AnimInstance->Montage_SetEndDelegate AnimInstance->OnPlayMontageNotifyBegin.AddDynamic AnimInstance->OnPlayMontageNotifyEnd.AddDynamic

You also should make sure to unbind your callbacks at the right moments.

The function which shows how to add is this:

 void UPlayMontageCallbackProxy::PlayMontage(class USkeletalMeshComponent* InSkeletalMeshComponent, 
     class UAnimMontage* MontageToPlay, 
     float PlayRate, 
     float StartingPosition, 
     FName StartingSection)
 {
     bool bPlayedSuccessfully = false;
     if (InSkeletalMeshComponent)
     {
         if (UAnimInstance* AnimInstance = InSkeletalMeshComponent->GetAnimInstance())
         {
             const float MontageLength = AnimInstance->Montage_Play(MontageToPlay, PlayRate, EMontagePlayReturnType::MontageLength, StartingPosition);
             bPlayedSuccessfully = (MontageLength > 0.f);
 
             if (bPlayedSuccessfully)
             {
                 AnimInstancePtr = AnimInstance;
                 if (FAnimMontageInstance* MontageInstance = AnimInstance->GetActiveInstanceForMontage(MontageToPlay))
                 {
                     MontageInstanceID = MontageInstance->GetInstanceID();
                 }
 
                 if (StartingSection != NAME_None)
                 {
                     AnimInstance->Montage_JumpToSection(StartingSection, MontageToPlay);
                 }
 
                 BlendingOutDelegate.BindUObject(this, &UPlayMontageCallbackProxy::OnMontageBlendingOut);
                 AnimInstance->Montage_SetBlendingOutDelegate(BlendingOutDelegate, MontageToPlay);
 
                 MontageEndedDelegate.BindUObject(this, &UPlayMontageCallbackProxy::OnMontageEnded);
                 AnimInstance->Montage_SetEndDelegate(MontageEndedDelegate, MontageToPlay);
 
                 AnimInstance->OnPlayMontageNotifyBegin.AddDynamic(this, &UPlayMontageCallbackProxy::OnNotifyBeginReceived);
                 AnimInstance->OnPlayMontageNotifyEnd.AddDynamic(this, &UPlayMontageCallbackProxy::OnNotifyEndReceived);
             }
         }
     }
 
     if (!bPlayedSuccessfully)
     {
         OnInterrupted.Broadcast(NAME_None);
     }
 }

more ▼

answered Apr 14 '19 at 06:58 AM

avatar image

Lardo Deepdelver
786 5 4 6

(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