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:
GetTexture2DByName(FName(*someFStringVariable));