Dynamic Load Object - Epic Wiki
# Dynamic Load Object
From Epic Wiki
Jump to: navigation, search
# Contents
- 1 Overview
- 2 Get Object's Path
- 3 My Templated Dynamic Load Object Function
- 4 Example Uses of The Template
# Overview
Dear Community,
here are my static library functions for saving a objects path and then loading an object dynamically from a path
I have a templated version of my dynamic load object function for your entertainment!
To test this you could remove the word static and put in any .h file of your choosing like player controller
# Get Object's Path
{
return NAME\_None;
}
//~
FStringAssetReference ThePath = FStringAssetReference(Obj);
if(!ThePath.IsValid()) return NAME_None;
//The Class FString Name For This Object FString Str = Obj->GetClass()->GetDescription();
Str += "'"; Str += ThePath.ToString(); Str += "'";
return FName(*Str); }
# Why FName?
Because in my In-Game editor I only save the asset references to binary file, and use Dynamic Load Object during the loading of a level, and
FName is half the size of FString, 8 compared to 16 bytes.
So I do it for Save File size-reduction reasons
# My Templated Dynamic Load Object Function
return Cast<ObjClass>(StaticLoadObject( ObjClass::StaticClass(), NULL,\*Path.ToString()));
}
# Example Uses of The Template
return LoadObjFromPath
// Load Material From Path static FORCEINLINE UMaterialInterface* LoadMatFromPath(const FName& Path) { if(Path == NAME_None) return NULL; //~
return LoadObjFromPath
// Load Static Mesh From Path static FORCEINLINE UStaticMesh* LoadMeshFromPath(const FName& Path) { if(Path == NAME_None) return NULL; //~
return LoadObjFromPath
Retrieved from "https://wiki.unrealengine.com/index.php?title=Dynamic_Load_Object&oldid=205"