I’m utterly confused… We have a need to spawn dynamic objects at run time from Blueprints (with path). However, we do not know before hand what object or what path need to be loaded. Hence we cannot pre-load it with ConstructorHelpers since it’s only allowed at Constructor. (We have too many objects to pre-loaded anyway…)
So, how exactly do you spawn dynamic actor from a file path? I can devise some round-about way to do it, but I’m sure there must be some correct/easier way to do this though…
“So, how exactly do you spawn dynamic actor from a file path?”
**Dynamic Load Object**
I have written functions for you as follows
1. how to get the path of any object
2. how to load an object from the path in #1
to do this in blueprints, write a Blueprint Node Library function that does what I posted for you above
If you have the engine source, take a look at Engine\Source\Runtime\Engine\Private\GameplayStatics.h and .cpp, they contain a lot of the code called by blueprints. A treasure trove of examples, really.
EDIT: and of course you can spawn the object with the proper class if you know it already instead of AActor…
Wow, ty. So I’ll try using StaticLoadObject instead. However, since Unreal have re-indexed all of its reference pages on the web, I couldn’t really go read its description.
Can you help explain just briefly the differences betweeen [StaticLoadObject()] and [ConstructorHelpers::FObjectFinder]?
We have only one custom class, however, they are saved as blueprints into different objects. So I’m not sure if I can load them via class name (plz, correct me if I’m wrong).
[World->SpawnActorDeferred] and [obj->OnConstruction] is truely something helpful that I haven’t known about though, so ty!
ps. Thxz again for all your wonderful tutorials, Rama. I know tons of people really appreciate your work here.
You could call StaticLoadObject instead, but ConstructorHelpers cache the pointer to the asset, so there is zero overhead each time you create your object, whereas StaticLoadObject does have an overhead where it searches for the object based on its name.
Also note that when you load objects by name, the packager won’t automatically know to cook/package those objects, so you will have to manually add them to the list in the ini file.