I have many animations of melee attacks.
I have all of them in one AnimMontage.
I would like to play the first animation, then if the player presses again the attack button playing the next one and so on, otherwise stop the AnimMontage from playing.
If I play an anim montage this way:
return GetPawnMesh()->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
How can I set what section to play each time on that AnimMontage and what can I set to stop it?
I have created a TestAnimMontage similar to the one I can see here:https://rocket.unrealengine.com/docs/ue4/INT/Engine/Subsystems/Animation/AnimMontage/index.html.
But I need to handle everything from code (if it is possible).
#AnimInstance.h
To do really fancy stuff and make your own modified anim montage playing code,
You should
- extend your own anim instance from UAnimInstance
- reparent your animation blueprint to use your anim instance
- check out these awesome functions!
#Functions of Great Pertinence
AnimInstance.h
/** Makes a montage jump to a named section. */
UFUNCTION(BlueprintCallable, Category="Animation")
void Montage_JumpToSection(FName SectionName);
/** Makes a montage jump to the end of a named section. */
UFUNCTION(BlueprintCallable, Category="Animation")
void Montage_JumpToSectionsEnd(FName SectionName);
/** Changes the next section in the montage to a different one. */
UFUNCTION(BlueprintCallable, Category="Animation")
void Montage_SetNextSection(FName SectionNameToChange, FName NextSection);
/** Returns the name of the current animation montage section. */
UFUNCTION(BlueprintCallable, Category="Animation")
FName Montage_GetCurrentSection();

Also, you can get and set exact positions as well!
/** Get Current Montage Position */
float Montage_GetPosition(UAnimMontage* Montage);
/** Has Montage been stopped? */
bool Montage_GetIsStopped(UAnimMontage* Montage);
/** Set position. */
void Montage_SetPosition(UAnimMontage* Montage, float NewPosition);
/** Get PlayRate */
float Montage_GetPlayRate(UAnimMontage* Montage);
/** Set PlayRate */
void Montage_SetPlayRate(UAnimMontage* Montage, float NewPlayRate);
/** Get next sectionID for given section ID */
int32 Montage_GetNextSectionID(UAnimMontage* Montage, int32 CurrentSectionID);
Thanks, I’ll start playing with them.
After having done all those steps can the general idea be:
- The input makes the AnimMontage to start playing
- The next input of the player calls JumpToSection to play the next attack animation inside the AnimMontage
- In case I have to stop the combo I use JumpToSectionsEnd.
As Montage_JumpToSection doesn’t take a AnimMontage as a parameter I suppose it is performed on the currently active AnimMontage. Isn’t it?
I am trying in this way just to run a test before start implementing my own code but I can’t switch section. Is my idea of playing the montage and then changine section wrong?
UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
FName name("Swing1");
UseMesh->AnimScriptInstance->Montage_JumpToSection(StartSectionName);
you are going to have to experiment and find out for yourself, I’ve not used these functions in depth yet.
If you encounter a specific issue that seems like a bug let us know!
Rama
well im not sure if it is a typo in your copy pasting
but this
FName name("Swing1");
UseMesh->AnimScriptInstance->Montage_JumpToSection(StartSectionName);
should definitely be this!
FName name("Swing1");
UseMesh->AnimScriptInstance->Montage_JumpToSection(name);
No, it was actually an error!!! I was passing another variable to it.
Currently I am using it and it seems to work well.
I’ll experiment a little with all the other functions.
Thanks.