# \[Question\] How to access variable from a Blueprints Event graph in C++

**URL:** <https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601>\
**Category:** Character & Animation\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [March 11, 2014, 2:31am UTC](https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601 "2014-03-11T02:31:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:31am UTC](https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601/1 "2014-03-11T02:31:23Z")

</div>

An example is I have an animation blueprint that has a has torch Boolean variable that blends the characters default walk animation with a idle animation of him holding a torch I’m wondering how I can get access to that variable from c++ code so I can toggle it at run-time… Is this possible? If so what function?

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:31am UTC](https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601/2 "2014-03-11T02:31:23Z")

</div>

Dear Aidan,

You should create the variable in the c++ instead, by creating your own custom animation blueprint class.

Then you need to re-parent your anim blueprint to use your custom animation blueprint class, and then the variable will appear in the right click menu

I do this all time so I know it will work for you 🙂

here’s the basic code for what you are asking

```
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "VictoryAnimInstance.generated.h"

UCLASS(transient, Blueprintable, hideCategories=AnimInstance, BlueprintType)
class UVictoryAnimInstance : public UAnimInstance
{
	GENERATED_UCLASS_BODY()
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Movement)
	bool UseBackwardsBlendSpace;
	
};

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "VictoryGame.h"

//////////////////////////////////////////////////////////////////////////
// UVictoryAnimInstance

UVictoryAnimInstance::UVictoryAnimInstance(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	UseBackwardsBlendSpace = false;
}

```

I have a tutorial on setting anim blueprint vars from C++ here

[http://forums.epicgames.com/threads/972861-Tutorial-Compile-C-for-UE4-Code-Samples-For-You-(New-Create-Material-Instances)?p=31653957&viewfull=1#post31653957](http://forums.epicgames.com/threads/972861-Tutorial-Compile-C-for-UE4-Code-Samples-For-You-(New-Create-Material-Instances)?p=31653957&viewfull=1#post31653957)

#Reparent That Anim BP

Dont forget to re-parent your anim BP after you compile your new source code!!

picture of this at the link above to my tutorial  
Rama

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:31am UTC](https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601/3 "2014-03-11T02:31:25Z")

</div>

Thanks Rama,

Funny enough my teammate went though your forum post himself and noticed that’s how you were doing it and we have been kinda debating it since. Should work for us but we shall keep you posed 🙂

Aidan

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 2:31am UTC](https://forums.unrealengine.com/t/question-how-to-access-variable-from-a-blueprints-event-graph-in-c/275601/4 "2014-03-11T02:31:25Z")

</div>

It’s really not compicated, especially if you add a reference to your custom anim class in your character class.

**This custom anim reference would get set during Post Init Components**

and then you can use that to get/set custom vars from the anim instance very easily

just please

ALWAYS CHECK

that the anim instance var is valid!

🙂

```
protected:
	
	//Anim Instance
	UDragonHumanAnimInstance *Animation;

void AVictoryDragonHuman::PostInitializeComponents()
{
	Super::PostInitializeComponents();	
//Retrieve Custom Anim Instance
	Animation = Cast( Mesh->GetAnimInstance() );
	
	//Could not retrieve anim instance?
	if(!Animation) return;

        //Animation->DoStuff()

}

```
