Download

Declaring a texture variable

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:



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):



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

Thanks in advance

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



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


in the constructor for the hud



// 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.

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

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

It is the FPS tutorial from the wiki page

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

… and thanks again! Have a nice evening

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