How to get a Texture2D (by name) in c++ and/or Blueprint?

So I know how to get objects by resource name in c++ using the following code: (example loading a DataTable)

ConstructorHelpers::FObjectFinder Resource(TEXT(“DataTable’/Game/Data/’”));

However, I believe (and maybe I’m wrong) you have to execute this code in a constructor. In my game I have level information stored in a DataTable. One of the columns in the DataTable is an FString that represents a texture resource that is to be used as a backdrop in the level. Now, at a later point in time when I load a level I would like to be able to get the texture by using the resource name. This code would not be part of a constructor but rather a generic method I create in my gameMode to get a Texture2D by resource name like so:

UTexture2D* MyGameMode::GetTextureResource(const FString resourceName) { return ??? }

I’m not sure how to implement such a method.

Another way would be to create a base blueprint that represents my level in C++ but I don’t know how to pass in the resource name as part of the constructor to my c++ class in order to take advantage of the ConstrutorHelper::FObjectFinder.

Am I going about this all wrong?

Thanks, -jv

If the texture is already loaded, you can use one of the FindObject() functions in order to get it.

Alternatively, if you need to load them asynchronously, you can check this out: Asynchronous Asset Loading | Unreal Engine Documentation