Hello!
I am having an issue with World Partition and it’s affect on procedurally spawned mesh during Runtime.
I have a blueprint that during Runtime spawnes a maze - C++ module calculates mathematics and then floor and walls are being spawned using SpawnActor and Set Static Mesh nodes.
The problem is this - it would seems that World Partition does not affect those objects that were placed on map during Runtime - in my understanding the mesh should be present on Persistent level before BeginPlay occures.
The solution seemed simple - I need the maze to be spawned before BeginPlay, so I should do so in Constuction Script. As I soon found out SpawnActor is not supposed to work inside Construction Script - the engine gives me a warning:
Warning: SpawnActor failed because we are running a ConstructionScript (StaticMeshActor)
and the message about using SpawnActors in Construction Script being unsafe.
So the solution to that problem was to replace SpawnActor for AddChildActorComponent. Testing that with simple blueprint that spawns a cube mesh on construction script works flawlessly - cube spawns, at Runtime World Partition working with it as it should - unloading the cube while moving far away from it and loading it back when approaching it.
Now back to the maze - by design there are a lot of pieces that forms the maze - a lot of walls and floor tiles. Spawning them using AddChildActorComponent is kinda working - the maze spawns as it should but by nature all spawned walls and floor tiles are being children of the blueprint itself and as such they are considered the whole entity. So World Partition unloads the whole maze and cannot operate on a separate walls, and due to the maze being huge that does not seems like the desired behavior.
So I stared thinking - maybe I could use Construction script to call a custom event that would have SpawnActors that would be fired before BeginPlay? But alas - the event is called, debug-print strings in it are working, but SpawnActors are just being ingored, nothing spawns.
There are a couple of ideas in my head - to try generating level at runtime, saving it, unloading and reloading it so it will be kinda ready with all the meshes present for World Partition to work properly, or somehow run the code just before BeginPlay event but without relying upon Construction script.
Any thoughts?