I want to make an actor that dynamically spawns other actors. For that my actor is calling GetWorld()->SpawnActor().
Also, I want that to happen in the Editor so I can easily see and work with the result. This means that I can, for instance, do that in BeginPlay(), so I tried doing it by overriding OnConstruction. It works - kinda:
There are many, many items being spawned, so OnConstruction is called numerous times, I still don’t know when. The documentation states “may get rerun in the editor when changing blueprints” but I’m not sure what that means - what blueprints are being changed?
If I set the current object to be the parent of the spawned objects, Unreal crashes. I do that by setting FActorSpawnParameters::Owner = this, which I’m not sure it’s the way to go about it.
Hi there! Can you tell more - for that purpose do you want to see spawned actors? To look at there locations, density, etc?Or do you want to edit their props, names and so on?
What you can do is create an editor utilities actor (or widget) to manage your actors in the world.
Create a new blueprint actor called BP_EditorUtilities
Add two variables ActorToSpawn (Actor class reference) and LocationToSpawn (Transform reference)
Make sure both variables have “Expose and Spawn” and “Instance Editable” checked.
Obviously, you can customize it make to make to much more than just spawning actors. Using tools like this can definitely help automate your level management.
EDIT: Oops I didn’t realize you were looking for a c++ solution. It should be fairly simple to migrate this blueprint to C++. I could write it out for you if you get stuck.
Alekann01, thanks a lot for your very detailed solution. I think the crux of it is the “call in editor” option, exactly what I’m looking for. I’ll look into how to do it in C++. Also, sorry for taking this long to look into your answer - I’m currently learning many different things and moving between topics rather erratically.
Sorry I know it’s been awhile since this post, but I’m trying to make something similar and the Spawn Actor button doesn’t show in editor if I make it as an Editor widget/actor, it only shows if it’s a normal blueprint
So I wanted to ask in your screenshot the button for custom event does show on your editor utilities widget so is there an extra step to enable it other than setting the event as “call in editor”?