I’m working on a system that will randomly generate levels. I’m basically trying to make a roguelike FPS out of well crafted rooms that spawn in random arrangements.
So far, I can create objects in the OnBeginPlay methods, but I was wondering if it may be more efficient to do some things at level load itself. I’d want to set up a correctly sized navigation mesh volume for example. At the moment, I have a blank level with a 20,000x20,000x20,000 navmesh volume, which works for now. I placed some breakpoints in constructors of objects that would spawn at level load time when loading a level I created in the editor, but it’s still not obvious to me how the whole level loading and actor spawning process works. The stack trace is full of unreal’s function invocation code when it’s spawning an actor on level start for the receiveBeginPlay event rather than what I was actually looking for, which is it finding some data in the level file and knowing that it must now spawn an actor of some type. I’d basically want to follow that same code path and spawn static actors in that same way instead of reading it from the file.
I was also thinking about how we’re supposed to go about saving and loading games. I saw these docs: Saving and Loading Your Game | Unreal Engine Documentation. But this talks about how to save simple things like variables. How do I save and load an entire level state, like if I was to do a quick save in the middle of a level.
Also, let’s say I have a networked game, what would be the best way to spawn a randomly generated level for all the people connected. I may send a random seed to each player at the start of the game, but if people join in the middle, I’d also need to send the states of actors themselves. If I make a level in the editor, I imagine each player first loads the level, and only the actors that aren’t static, like weapons, projectiles, characters, debris get updated. But if the level is created dynamically, I’d have to “load” the static parts first myself instead of from a file. I’d imagine loading a quick save is a bit like joining in the middle of a multiplayer match as well.