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"

Notifies vs Timers for Animation Montage

Hullo,

I've got another animation question. I want to run an animation montage from C++, which I can now largely do, but I want to run a C++ function when it finishes. There are two primary ways to do this.

I can do it with a timer with something like the following:

 void AMGCharacter::OnPrimaryAttackPressed()
 {
     bIsPrimaryAttacking = true;
     float duration = PlayCombatAnimation(PrimaryAttack);
     PlayingAnimation = PrimaryAttack;
     GetWorldTimerManager().SetTimer(TimerHandle_OnCombatAnimationFinished, this, &AMGCharacter::StopCurrentCombatAnimation, duration, false);
     bIsCombatAnimating = true;
 }

Or I can do it with a notification. To do it with a notification right now, I can make a notification in the animation and then wire a Blueprint to call a C++ function to finish the animation.

Two questions:

  1. If I define a custom UAnimNotify type, such as UAttackEndedAnimNotify, how would I get the pointer to this notify, if there is one, from the animation montage and set a delegate for the call on notify? Or should I set up for this notify to always get the mesh, then the character, then cast to my character type (is this possible), and always run a particular function form there?

  2. If I can set up the notification from C++, would it still be preferably to use the timer method? This is how it's done in the ShooterGame. It's much simpler, but I'm not sure it would be better (or at least I'm not sure what I'd be missing out on).

Product Version: UE 4.12
Tags:
more ▼

asked Jul 16 '16 at 12:34 AM in C++ Programming

avatar image

calembendell
442 34 34 66

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hi, take a look at my answer here it may guide you !

Best regards.

more ▼

answered Jul 17 '16 at 10:39 AM

avatar image

NymKappa
692 31 20 54

avatar image calembendell Jul 17 '16 at 06:20 PM

Hey Joris, thanks for the response! Your example is very useful, but I don't see in that thread where timers vs notifiers are compared, and I don't see how to get a pointer to the notify from PlayAnimMontage or PlayAnimation. Do you have a comparison for the two methods and know how to get a pointer to the nofity from the pawn class calling the animation to play?

avatar image NymKappa Jul 18 '16 at 08:30 AM

Yeah that'a a partial response :D. Just like that I would say that you will encounter synchronization issues with timers, cause obviously timers will have a "hard coded" length while notification callbacks will fired at any time so you don't have to think about it.

About "How to get notifies pointer" try something like GetMesh()->GetAnimInstance()->GetCurrentActiveMontage()->GetAnimNotifies()

(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