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"

Movement and playing animation

Hello. I am working at movement animations. I have Bind Axis (which means the function is called in every frame). If Value = 0 then there is no movement, if 1 or -1 then character is moving. But the animations are played non-stop.

I need check what animation is already playing or something like this, but idk how. Now the animations is overlap and this is not working correctly.

UCharacterMovementComponent* CharacterMovement = GetCharacterMovement();

CharacterMovement IsWalking() is always true...

I will be grateful for your help

 void ASieCharacter::MoveForward(float Value)
     if ((Controller != NULL) && (Value != 0.0f))
         // find out which way is forward
         const FRotator Rotation = Controller->GetControlRotation();
         const FRotator YawRotation(0, Rotation.Yaw, 0);
         // get forward vector
         const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
         AddMovementInput(Direction, Value);
     if (Value == 0.0f)
         FName anis("/Game/LowPolySkeleton/Skeleton_Mage/Anims/mage_idle_1.mage_idle_1");
         UAnimationAsset*animIns = Cast<UAnimationAsset>(StaticLoadObject(UAnimationAsset::StaticClass(), NULL, *anis.ToString()));
         this->GetMesh()->PlayAnimation(animIns, true);
     else {
         FName anis("/Game/LowPolySkeleton/Skeleton_Mage/Anims/mage_run.mage_run");
         UAnimationAsset*animIns = Cast<UAnimationAsset>(StaticLoadObject(UAnimationAsset::StaticClass(), NULL, *anis.ToString()));
         this->GetMesh()->PlayAnimation(animIns, true);
Product Version: UE 4.18
more ▼

asked Mar 01 '18 at 08:09 AM in C++ Programming

avatar image

12 9 12 16

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

1 answer: sort voted first

Hey, why you make your life so hard with this code? :)

Use Animation blueprint, this is exactly why epic did Animation Blueprint! Animation blueprint is a state machine animation system which works with different states and you dont need handle blends or anything else between animations, you need only do the logic what and where can blend!!!


From other side, your code is totally wrong.. because you looped the animations and play simple anim asset should be not override each others...

If you really wanna handle animation playing from code instead of Animation Blueprint (REALLY REALLY NOT SUGGESTED) you should play anim montages instead of anim assets..

you can read about animmontage here: https://docs.unrealengine.com/latest/INT/Engine/Animation/AnimMontage/

hope this helps. cheers

more ▼

answered Mar 01 '18 at 08:54 AM

avatar image

1.5k 15 9 33

avatar image PanKamil897 Mar 01 '18 at 10:19 AM

Awesome! Anim blueprints is fantastic. What you think about mixing blueprints with c++?

avatar image AmphDev Mar 01 '18 at 10:36 AM

Go ahead sir! :) Dont be afraid using blueprints as finsl configurable class or animbp for your characters! Blueprints is great tool to avoid hardcoding and if you use them smart, you never notice any performance difference between blueprint and c++ I mean obviously do not spawn 10000 blueprint actor with tick enabled in your world. If you need 10k ticking actor just use pure c++ classes (or nativize your bp) But using animbp and exposing variables from your c++ class to bp for easy setup make sense :)

(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