HUD Class

Hi all.

I’m following this guide and I’ve run into problems compiling the HUD Class section. Not sure if I’ve made a mistake reading the instructions or what. Any ideas what im doing wrong?


Thanks in advance all!

you put code in the wrong place

take



static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(TEXT("Texture2D'/Game/crosshair.crosshair'"));
CrosshairTex = CrosshairTexObj.Object;

and move it to the romhud.cpp file inside the constructor (function at top)

If you are always using the same texture for your crosshair you could also set CrosshairTex to be an UPROPERTY() making it able to be edited within the editor. Another way would be exposing the string (Texture2D’/Game/crosshair.crosshair’) in an UPROPERTY() and use that in your code in the same place as stated by CNKIT. The third option is to expose a FStringAssetReferences and then load it when you need the asset: Asynchronous Asset Loading | Unreal Engine Documentation.

Using async loading will work best because hard referencing assets will force them to be loaded always in a cooked build (packaged standalone), so the way to save memory is to only load what is required.