# Get Blueprint Animation variables in C++?

**URL:** <https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927>\
**Category:** Editor Scripting\
**Tags:** Variable, unreal-engine, question\
**Created:** [September 12, 2015, 1:30am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927 "2015-09-12T01:30:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juice-Tin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/juice-tin/32/1008648_2.png) [@Juice-Tin](https://forums.unrealengine.com/u/Juice-Tin)\
**Post date:** [September 12, 2015, 1:30am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/1 "2015-09-12T01:30:36Z")

</div>

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(){
	Super::BeginPlay();
	Animation = Mesh->GetAnimInstance();
}
void AUnit::Tick(float DeltaTime){
	Super::Tick(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++){
		AnimNotifies[i]->NotifyName.ToString();
	}

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

```

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! 🙂

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [September 12, 2015, 2:12am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/2 "2015-09-12T02:12:34Z")

</div>

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

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![Juice-Tin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/juice-tin/32/1008648_2.png) [@Juice-Tin](https://forums.unrealengine.com/u/Juice-Tin)\
**Post date:** [September 12, 2015, 4:26pm UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/3 "2015-09-12T16:26:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [September 15, 2015, 3:17am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/4 "2015-09-15T03:17:32Z")

</div>

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

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

…

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:

> **[How to access blueprint vars in c++?](https://forums.unrealengine.com/questions/2145/how-to-access-blueprint-vars-in-c.html)**
>
> How can I acces vars I’ve created in my Character’s blueprint in the c++ character class code?

---

<div class="post-metadata">

**Author:** ![Juice-Tin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/juice-tin/32/1008648_2.png) [@Juice-Tin](https://forums.unrealengine.com/u/Juice-Tin)\
**Post date:** [September 16, 2015, 12:31am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/5 "2015-09-16T00:31:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![emperor\_katax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emperor_katax/32/1070178_2.png) [@emperor\_katax](https://forums.unrealengine.com/u/emperor_katax)\
**Post date:** [December 22, 2018, 11:00am UTC](https://forums.unrealengine.com/t/get-blueprint-animation-variables-in-c/331927/6 "2018-12-22T11:00:59Z")

</div>

check this as well:

> **[Get / Set variables by Name | Shooter Tutorial](http://shootertutorial.com/2016/03/20/get-set-variables-by-name/)**
