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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to play animations by code?

I after a created a Pawn Class and set up movement, I was wondering how to go about applying my animations to each specific direction of movement, such as walking forward(to play forward animation, ect). What functions/code would I be working with to achieve this? Also, how do I reference my animations through code?

Product Version: UE 4.9
Tags:
more ▼

asked Nov 06 '15 at 12:04 AM in C++ Programming

avatar image

LostScout
135 18 28 35

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

2 answers: sort voted first

Hello LostScout,

Here is a small code snippet. You can try to create the AnimSequence in your character and play it.

Creating of animation:

YourCharacter.h

 UAnimSequence *Anim;
 
 class YourCharacter : public ACharacter
 {
     ...
     
     UAnimSequence *Anim;
     
     ...
 }

YourCharacter.cpp

 ...
 
 AMyProject3Character::AMyProject3Character()
 {
     ...
     
     static ConstructorHelpers::FObjectFinder<UAnimSequence> anim(TEXT("AnimSequence'/Game/Mannequin/Animations/ThirdPersonJump_Start.ThirdPersonJump_Start'"));
     Anim = anim.Object;
     
     ...
 }
 
 ...

Playing animation:

 ...
 
 bool bLoop = false;
 GetMesh()->PlayAnimation(Anim, bLoop);
 
 ...

AnimSequence'/Game/Mannequin/Animations/ThirdPersonJump_Start.ThirdPersonJump_Start' - reference of your AnimSequence from engine.

Hope this helps.

more ▼

answered Nov 06 '15 at 07:56 AM

avatar image

Artem Gergel'
245 19 3 20

avatar image LostScout Nov 06 '15 at 07:20 PM

Would I specify/call the play animation function in my MoveForward() function. I want the result to be every time the player walks forward, the respective animation play. Would this be the right way to go about achieveing this?

avatar image Mark James G Nov 08 '15 at 11:33 PM

You'll want to make your own state machine. A series of booleans called via tick. If you want a better idea of this download the Paper2D C++ module and give that a look at.

I think it has something like UpdateAnimation();. So from there you can get an idea on how to make this work.

avatar image Jocko Jonson Dec 15 '15 at 05:11 PM

OMG, thank you for this. There is zero documentation about doing this in code. The docs say "you can play animations from code" but never actually show how.

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

answered Dec 15 '15 at 10:54 PM

avatar image

rantrod
1.5k 48 47 216

(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