Finding texture2d from a fstring at runtime

Hello, I have a FString variable that has my relative path to the uasset texture. How do I use the variable in getting the utexture2d object?

static ConstructorHelpers::FObjectFinder CrosshairTexObj(TEXT(“Texture2D’%s’”), someFStringVariablePath);

Looks like that code above is just for construct. Is there something similar for runtime?

I don’t think Texture2D is actually needed in that.

static ConstructorHelpers::FObjectFinder CrosshairTexObj(TEXT(someFStringVariablePath);

After some more research, I believe ConstructorHelpers::FObjectFinder is not the function I’m looking for. Because it seems to be only for ObjectInitializer.

I’m getting paths from json files at run time. These paths are relative paths to already imported textures. I just need to know how to convert these FString paths that I’m getting from the json files to a texture2d.

I found the solution here:

header file:

template <typename ObjClass>
static FORCEINLINE ObjClass* LoadObjFromPath(const FName& Path)
	if (Path == NAME_None) return NULL;

	return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), NULL, *Path.ToString()));

static FORCEINLINE UTexture2D* GetTexture2DByName(const FName& Path)
	if (Path == NAME_None) return NULL;

	return LoadObjFromPath<UTexture2D>(Path);

C++ file:


I want to create a Texture2D dynamically which is readable. There doesn’t appear to be any way to set the IsReadable property to true. The docs reference IsReadable, but I can’t even find it declared anywhere.