# How get the animation blend weight of some state in C++

**URL:** <https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915>\
**Category:** Character & Animation\
**Tags:** unreal-engine, CPP, question\
**Created:** [December 12, 2016, 2:13am UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915 "2016-12-12T02:13:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8366a311](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8366a311](https://forums.unrealengine.com/u/anonymous_user_a8366a311)\
**Post date:** [December 12, 2016, 2:13am UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/1 "2016-12-12T02:13:01Z")

</div>

Hi Guys,

I need to know how get the current blend weight of some state on the AnimGraph/StateMachine using C++. Exactly the same thing that you can do in Blueprint (AnimBlueprint/AnimGraph) using “State Weight” node.

In UAnimInstance we have this function: float GetInstanceStateWeight(int32 MachineIndex, int32 StateIndex); exactly for that, but require the StateIndex and that is the problem. I can’t found a way to get the StateIndex from a FName.

I was trying this:

```
int32 MachineIndex = GetStateMachineIndex(StateMachineName);
FAnimNode_StateMachine* MachineInstance = GetStateMachineInstance(MachineIndex);
if (MachineInstance)
{
	const FBakedAnimationStateMachine* MachineDescription = MachineInstance->GetMachineDescription();
	int32 StateIndex = MachineDescription->FindStateIndex(StateName);
}

```

but FAnimNode\_StateMachine::GetMachineDescription() is protected ☹

Someone can help me with this, please ?

Thanks

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8366a311](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8366a311](https://forums.unrealengine.com/u/anonymous_user_a8366a311)\
**Post date:** [December 14, 2016, 1:21pm UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/2 "2016-12-14T13:21:20Z")

</div>

hellooo… someone here ? 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8366a311](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8366a311](https://forums.unrealengine.com/u/anonymous_user_a8366a311)\
**Post date:** [December 16, 2016, 2:04pm UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/3 "2016-12-16T14:04:23Z")

</div>

bump, bump …

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8366a311](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8366a311](https://forums.unrealengine.com/u/anonymous_user_a8366a311)\
**Post date:** [December 19, 2016, 8:48pm UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/4 "2016-12-19T20:48:12Z")

</div>

… no one can point me in the right direction here ?

---

<div class="post-metadata">

**Author:** ![Arnleif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arnleif](https://forums.unrealengine.com/u/Arnleif)\
**Post date:** [February 10, 2017, 8:38am UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/5 "2017-02-10T08:38:24Z")

</div>

Hi. Came across your post here as I was looking to get the state weight myself from blueprint.  
I did not manage to do that (within regular blueprint, I know it can be done in the animblueprints state and machine -graph).

Using your code I ended up with this that works, at least for me:

```
float APlayerCharacter::GetStateWeight( FName machineName, FName stateName ) const
{
	float weight = 0;
	UAnimInstance* animInstance = Mesh1P->GetAnimInstance();
	if (animInstance)
	{
		FAnimNode_StateMachine* machine = animInstance->GetStateMachineInstanceFromName(machineName);
		if( machine )
		{
			IAnimClassInterface* iface = IAnimClassInterface::GetFromClass( animInstance->GetClass() );
			const FBakedAnimationStateMachine* baked = animInstance->GetMachineDescription( iface, machine );

			if( baked )
			{
				int stateIdx = baked->FindStateIndex( stateName );
				if( stateIdx != INDEX_NONE )
				{
					return machine->GetStateWeight( stateIdx );
				}
			}
		}
	}

	return weight;
}

```

( I actually expect that there is a way to get the weight already in blueprint and that I haven’t found it yet. Anything else would just be very lacking for such an engine… )

---

<div class="post-metadata">

**Author:** ![MingYueMeow](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MingYueMeow](https://forums.unrealengine.com/u/MingYueMeow)\
**Post date:** [May 13, 2021, 9:10am UTC](https://forums.unrealengine.com/t/how-get-the-animation-blend-weight-of-some-state-in-c/378915/6 "2021-05-13T09:10:48Z")

</div>

Work like a charm! Thx
