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"

Get Blueprint Animation variables in C++?

Hello, I've been able to get Curves and Notify's from animations just fine, but I'm having a hard time getting or setting animation variables so the animations will actually play.

Here is how I got the curves and notifys:

 void AUnit::BeginPlay(){
     Animation = Mesh->GetAnimInstance();
 void AUnit::Tick(float DeltaTime){

     //Get Animation Curve
     float val = Animation->GetCurveValue(FName("Curve"));

     //Get Animation Notifies
     TArray<const struct FAnimNotifyEvent*> AnimNotifies = Animation->AnimNotifies;
     for (int i = 0; i < AnimNotifies.Num(); i++){

     //Get/Set Animation Variables.. These are fake, 
     //but I'm looking for something like this:
     Animation->SetBool("inAir", true);

Now I can't seem to figure out how to access the variables through the AnimInstance.

Any help would be greatly appreciated! Thanks!

Bonus: If you know how to directly play/crossfade an animation through code that would be great too! :)

Product Version: UE 4.9
more ▼

asked Sep 12 '15 at 01:30 AM in C++ Programming

avatar image

152 38 37 45

avatar image rantrod Sep 12 '15 at 02:12 AM

Maybe different than you're thinking but does this help?


avatar image Juice-Tin Sep 12 '15 at 04:26 PM

Edit: I ended up using that method. The code on that page has some errors as it's a few years old and it's missing some steps, but in the end it works. If you want to post that as an answer, I'd be glad to mark it as the correct asnwer.

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

1 answer: sort voted first

I have two options for you. First is the way I suggested already. It's the answer usually given:



Second Option:

     if (USkeletalMeshComponent *Mesh = MyActor->FindComponentByClass<USkeletalMeshComponent>())
         if (UAnimInstance *AnimInst = Mesh->GetAnimInstance())
             UFloatProperty* MyFloatProp = FindField<UFloatProperty>(AnimInst->GetClass(), AnimPropName);
             if (MyFloatProp != NULL)
                float FloatVal = MyFloatProp->GetPropertyValue_InContainer(AnimInst);
                MyFloatProp->SetPropertyValue_InContainer(AnimInst, 180.0f);
                FloatVal = MyFloatProp->GetPropertyValue_InContainer(AnimInst);

I put a way to get and to set in there.

This technique also works with regular blueprints, not just anim blueprints and with other types:

    UBoolProperty* BoolProp = FindField<UBoolProperty>(MyActor->GetClass(), PropName);
     if (BoolProp != NULL)
         bool BoolVal = BoolProp->GetPropertyValue_InContainer(Actor1);
         BoolProp->SetPropertyValue_InContainer(Actor1, true);

The names are just simple FName data types:

 FName PropName = TEXT("MyBoolVariable");
 FName AnimPropName = TEXT("MyFloatVariable");

Here's the source I got it from:


more ▼

answered Sep 15 '15 at 03:17 AM

avatar image

1.5k 49 47 216

avatar image Juice-Tin Sep 16 '15 at 12:31 AM

I used the first method, ended up working very nicely, thankyou. :)

(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