All that AGameMode overrides will not help, if you want to add actors to the world in edit mode, befor clicking play.
I want to create an actor object before play mode starts and see it in the editor. How?
All that AGameMode overrides will not help, if you want to add actors to the world in edit mode, befor clicking play.
I want to create an actor object before play mode starts and see it in the editor. How?
The world is an Editor World not a Game World. When you hit play the editor creates a new Game Instance with it’s own world etc, but the editor world is still there in the background. You can access it should you need to, but that’s obviously a bad idea because it won’t work in a packaged game. When using TObjectIterator for example, you have to check what world the objects are in or you can end up accessing objects in the wrong world…
You can use Delayed Match Start in AGameMode, spawn actors you need to spawn before gameplay starts and then your gamemode will begin. You will have to write some functionality to support that though, like a pre-match / warmup system. ShooterGame has one.
If you need them to spawn earlier than that, then you’ll have to look into the GameInstance and write out whatever you want to do in the InitGame() function, which is the entry point for virtually any game. Either way you still can’t spawn things *before *clicking ‘Play’, unless you mean instantly when you click ‘Play’?
Thank you for the answer and the hint for Editor World / Game World.
I want to generate procedural content at edit time. So you mean, I can’t spawn an actor using an Editor World?
You can spawn into the editor world, but you will need to have an override of a class that exists when the editor world exists. I override the UEditorEngine class, and do my spawning in there.