# Declaring a texture variable

**URL:** <https://forums.unrealengine.com/t/declaring-a-texture-variable/7666>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 15, 2014, 11:21pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666 "2014-07-15T23:21:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [July 15, 2014, 11:21pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/1 "2014-07-15T23:21:55Z")

</div>

Hey! Forgive me for the noob question but I am new to C++

So I made a class deriving from the HUD class and set up a Texture Variable in the Header-File:

```auto

UPROPERTY()
UTexture2D* ButtonBG;

```

How do I give that Variable a value in the CPP-File, because this doesn’t work (but would have in Unreal Script):

```auto

ButtonBG = Texture2D'/Game/HUD/GFX/TextButtons_Comb_00.TextButtons_Comb_00';

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![warlord57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@warlord57](https://forums.unrealengine.com/u/warlord57)\
**Post date:** [July 16, 2014, 12:10am UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/2 "2014-07-16T00:10:09Z")

</div>

This is how I get the crosshair texture in my hud. I am assuming it is exactly what you are needing to do.

in the hud header file

```auto

/** Crosshair asset pointer */
UTexture2D* CrosshairTex;

```

in the constructor for the hud

```auto

// Set the crosshair texture
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(TEXT("Texture2D'/Game/Textures/crosshair.crosshair'"));

if (CrosshairTexObj.Object != NULL)
{
	CrosshairTex = CrosshairTexObj.Object;
}

```

I hope this helps you. I got this from a tutorial which is how I learned how to get the textures into the code.

---

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [July 16, 2014, 7:33pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/3 "2014-07-16T19:33:31Z")

</div>

Thank you very much, warlord. It worked like a charm. 🙂

Would you mind telling me your tutorial resources… I could need some

---

<div class="post-metadata">

**Author:** ![warlord57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@warlord57](https://forums.unrealengine.com/u/warlord57)\
**Post date:** [July 16, 2014, 7:42pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/4 "2014-07-16T19:42:50Z")

</div>

It is the FPS tutorial from the wiki page

> **[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 — ue4community.wiki! You will be able to find content from the official...

That helped me understand how to get a quick FPS game up and running from a blank c++ project.

---

<div class="post-metadata">

**Author:** ![Pseudocorpus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pseudocorpus/32/453689_2.png) [@Pseudocorpus](https://forums.unrealengine.com/u/Pseudocorpus)\
**Post date:** [July 16, 2014, 8:04pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/5 "2014-07-16T20:04:23Z")

</div>

… and thanks again! Have a nice evening

---

<div class="post-metadata">

**Author:** ![LuisAlaguna](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/luisalaguna/32/570408_2.png) [@LuisAlaguna](https://forums.unrealengine.com/u/LuisAlaguna)\
**Post date:** [August 8, 2019, 1:12pm UTC](https://forums.unrealengine.com/t/declaring-a-texture-variable/7666/7 "2019-08-08T13:12:47Z")

</div>

> [@warlord57](#):
>
> This is how I get the crosshair texture in my hud. I am assuming it is exactly what you are needing to do.
> 
> in the hud header file
> 
> ```auto
> 
> /** Crosshair asset pointer */
> UTexture2D* CrosshairTex;
> 
> ```
> 
> in the constructor for the hud
> 
> ```auto
> 
> // Set the crosshair texture
> static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(TEXT("Texture2D'/Game/Textures/crosshair.crosshair'"));
> 
> if (CrosshairTexObj.Object != NULL)
> {
> CrosshairTex = CrosshairTexObj.Object;
> }
> 
> ```
> 
> I hope this helps you. I got this from a tutorial which is how I learned how to get the textures into the code.

Don’t forget put this in the class’s constructor.
