Download

Possible to declare a static texture2d that can be updated via blueprint?

Hi I am trying to set an icon for say a weapon. I have an array of the weapon classes but I would like to access the icon texture for my hud without creating an instance of that weapon. say because I am create and destroy the weapons as you equip them, so something like:

MyWeapon::RadialIcon

would be perfect but this wont compile:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Bear”)
static UTexture2D* RadialIcon;

nor

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Bear”)
static const UTexture2D* RadialIcon;

any ideas? is it even possible?

I recently tried something similar.

Working solution right now is:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Bear”)
TAssetPtr<UTexture2D> RadialIcon;

In the Blueprint: get class -> get class defaults -> RadialIcon -> Resolve Asset

What I also tried:
Get ClassDefaults won’t return a UTexture2D* because in Blueprints it cannot be guaranteed to be read-only. (That was said by someone from Epic on AnswerHub).

A workaround would be to wrap the UTexture2D* in a USTRUCT, which is available from GetClassDefaults, breaking the struct and then using the UTexture2D*. But working with it, I got errors à la “Graph is linked to external object” (or something similar). Long story short, using the Asset ID Pointer as shown above works with GetClassDefaults.

you could use a UDataAsset to store icons, that you can also access from your blueprinted weapons easily.

Hi,

I recently tried exactly that. Working Solution:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = “Bear”)
TAssetPtr<UTexture2D> RadialIcon;

In Blueprint: Get Class -> Get Class Defaults -> RadialIcon -> Resolve Asset

What I also tried:

Using a UTexture2D* with GetClassDefaults doesn’t work. On the AnswerHub, someone from Epic pointed out that this is normal behaviour because the UTexture2D reference cannot be guaranteed to be read-only in Blueprint.

Workaround is to wrap the UTexture2D* in a USTRUCT. But getting the UTexture2D* from the struct using getclassdefaults and then trying to pass the reference gave me errors along the lines of " graph is linked to external private object". Long story short, use the AssetPointer

I just need to access the asignment of the object on the bp, dont care for it on the graph. Basically I need something equivalent to static functions in udk

k got it, you can do this:

ExampleClass.h

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = “Bear”)
UTexture2D* RadialIcon;

FORCEINLINE UTexture2D* GetRadialIcon() { return RadialIcon; }

and then access it like:

ExampleClass.GetDefaultObject()->GetRadialIcon();