Getting UTexture*, but not in constructor

I need to find a UTexture pointer, but I’ve just realize that I can’t do it in the constructor. Until now I’ve been using:

FString Path = TEXT("/Path/..");

static ConstructorHelpers::FObjectFinder<UTexture> TexReference(*(TexPath));

UTexture * Texture = TexReference.Object();

Trouble is, I’ve just discovered the hard way that ConstructorHelpers::FObjectFinder only works in the constructor (not surprising really, considering it’s name!). Is there a way to do this elsewhere? I think it’s possible with LoadClass, but I can’t get it to work.

Thanks

This might be what you are looking for: https://answers.unrealengine.com/questions/368239/change-characters-material-at-runtime-using-c.html

Its about finding and loading a specific material during runtime (after the constructor is called, during BeginPlay).

You can do this with LoadObject:

UTexture * Texture = LoadObject(nullptr, *TexPath);

Not sure how this affects performance, but it works for me!

1 Like