I'm trying to load an .fbx file from an external file to my game during gameplay. I have created a function to load a mesh from path, however the function ''LoadMeshFromFile'' returns NULL, I tried to change the path to the path of an existing .uasset and it works fine, however my goal is to import an .fbx file to the game during gameplay instead, so why when I use a path to an .fbx file on my disk it keeps returning NULL, is there a way to make it work? Here is my code:
UStaticMeshComponent* UObjectsCreator::CreateMeshComponentFromStaticMesh(const FName& Path)
{
UStaticMeshComponent* MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MyNewStaticMeshComponent"));
MeshComponent->SetStaticMesh(LoadMeshFromPath(Path));
return MeshComponent;
}
// Load Static Mesh From Path
UStaticMesh* UObjectsCreator::LoadMeshFromPath(const FName& Path)
{
if (Path == NAME_None) return NULL;
//~
return LoadObjFromPath<UStaticMesh>(Path);
}
//TEMPLATE Load Obj From Path
template <typename ObjClass>
ObjClass* UObjectsCreator::LoadObjFromPath(const FName& Path)
{
if (Path == NAME_None) return NULL;
//~
return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), NULL, *Path.ToString()));
}
You can't load an fbx file directly at runtime in ue4. You need to use some external plugin to do that