From Trying to load Material with absolute path - #2 by adludum
template <typename ObjClass>
static FORCEINLINE ObjClass* LoadObjFromPath(const FName& Path)
{
if (Path == NAME_None) return nullptr;
return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), nullptr, *Path.ToString()));
}
static FORCEINLINE UMaterial* LoadMaterialFromPath(const FName& Path)
{
if (Path == NAME_None) return nullptr;
return LoadObjFromPath<UMaterial>(Path);
}
Then load the UMaterial:
static const TCHAR* MaterialPath = TEXT("/Path/Of/M_Mat.M_Mat");
UMaterial* Material = LoadMaterialFromPath(MaterialPath);