# getting variables from a cpp/h file to be read by another cpp file

**URL:** <https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [June 26, 2014, 9:11pm UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714 "2014-06-26T21:11:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_2fe3904e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2fe3904e](https://forums.unrealengine.com/u/anonymous_user_2fe3904e)\
**Post date:** [June 26, 2014, 9:11pm UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/1 "2014-06-26T21:11:03Z")

</div>

hi I have created a new AnimInstance because I want to include some custom variables in my animation graph, but I want to be able to edit them in my character.cpp file  
so in my NewAnimInstance.h file ive got

```
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
float AnimationNumber;

```

and in my Player1Character.cpp i’ve written #include “NewAnimInstance.h”, but when I write AnimationNumber in the Player1Character.cpp, I get an error saying its not recognized. Im not that experienced with C++ so I dont know how to go about this, can someone help?

---

<div class="post-metadata">

**Author:** ![staticvoidlol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@staticvoidlol](https://forums.unrealengine.com/u/staticvoidlol)\
**Post date:** [June 27, 2014, 5:08am UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/2 "2014-06-27T05:08:16Z")

</div>

Please don’t take this the wrong way, but I’d suggest that you brush up on some introductory programming/C++ tutorials to get the basics under the belt.  
As for your specific question, you first need a reference to an instance of your AnimInstance class, e.g.

```auto

AnimInstance = Cast<UYourAnimInstanceClass>(SkleletalMeshCompRef->GetAnimInstance());
AnimInstanc->AnimationNumber = 27.0f;

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2fe3904e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2fe3904e](https://forums.unrealengine.com/u/anonymous_user_2fe3904e)\
**Post date:** [June 27, 2014, 9:51am UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/3 "2014-06-27T09:51:02Z")

</div>

I tried that a little later after some research, I found this site

> **[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...

I followed it to the letter but its not recognizing UMyAnimInstanceClass in the character class.

PlayerCharacter.cpp

```auto

void APlayerCharacter::TurnAtRate(float Rate)
{
	// calculate delta for this frame from the rate information
	AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
	UMyAnimInstance * Animation = Cast<UMyAnimInstance>(Mesh->GetAnimInstance());
	Animation->AimRight += Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds();
}

```

MyAnimInstance.h

```auto

#pragma once

#include "Animation/AnimInstance.h"
#include "MyAnimInstance.generated.h"

/**
*
*/
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
class UMyAnimInstance : public UAnimInstance
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
		float AimUp;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
		float AimRight;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
		bool Running;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
		bool Jumping;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
                float AnimationNumber 
};

```

is there something im missing?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ccd38332](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ccd38332](https://forums.unrealengine.com/u/anonymous_user_ccd38332)\
**Post date:** [June 27, 2014, 10:14am UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/4 "2014-06-27T10:14:04Z")

</div>

Sorry for this kind of basic question but, did you include MyAnimInstance.h in the PlayerCharacter.cpp?

Else, check the typo ^^’

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2fe3904e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2fe3904e](https://forums.unrealengine.com/u/anonymous_user_2fe3904e)\
**Post date:** [June 27, 2014, 10:28am UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/5 "2014-06-27T10:28:41Z")

</div>

> [@Navezof;85292](#):
>
> Sorry for this kind of basic question but, did you include MyAnimInstance.h in the PlayerCharacter.cpp?
> 
> Else, check the typo ^^’

\*\*\*\* me,  
no I didnt,

I did at one point and I got it working, but I had to start over cuz of a crash. It wasnt mentioned in the tutorial so I didnt notice.  
thnx

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ccd38332](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ccd38332](https://forums.unrealengine.com/u/anonymous_user_ccd38332)\
**Post date:** [June 27, 2014, 12:18pm UTC](https://forums.unrealengine.com/t/getting-variables-from-a-cpp-h-file-to-be-read-by-another-cpp-file/6714/6 "2014-06-27T12:18:31Z")

</div>

^^

Always check the basic stuff before everything else. If something is unrecognized it basicaly mean it didn’t find the declaration of the variable. And as the declaration of variable in C++ are often (not always) in the header file, you have to tell the cpp file which header file he should use. This is why you have to #include the corresponding header file where the required variable are.
