I have a blueprint construction script which spawns ChildActorComponents so I can fill a level with actors through it. This works. When I try to do this in c++ (note not the constructor, but AActor::OnConstruct) all of the spawned actors remain when the method is called again, leading to duplicates. I expected it to clean its state before running just like the blueprint version does. What am I missing?
I looked at the AddComponent node in blueprint which does a lot of other stuff but is marked as “for blueprint use only” which is funny because it does a ton of magic behind the scenes that I don’t do the “normal” way.
If I’m not mistaken OnConstruction() gets called after BP constructor and believe it only serves like a notificacion that construction (including BP) has ran. Since the actor is already created and setup it will keep adding more components because that is what its being told to do.
Hello, sorry for not replying earlier I had to work on a few patches. I wasn’t expecting that there is nothing like the c++ version of the blueprint’s construction script and I found quite a few things.
Actors spawned through a child actor component don’t show their properties on the editor panel.
The purpose of spawning on construction script vs OnBeginPlay is to preview spawns on positions (think of an airplane on an airbase), otherwise there is no reason to.
Optimally, there’d be no child actor components, they are only there to hack spawn during construction script.
The past days I’ve been working on a spawn system which responds after BeginPlay to certain events and I realized that if I’m going to spawn things procedurally based on certain world events, I can’t have them on the editor in the first place. I need some… Editor utility. I just went with that on BeginPlay and gave the idea some rest.
Perhaps that would be the better option, removing all logic from construction script, removing the child actor components, spawn the normal way during BeginPlay. Any point I mark in the editor as a spawn point (by placing a spawner actor manually) would be read by some form of editor utility to perhaps show decoys or sprites where things are going to be. I haven’t yet given it enough thought. But then the editor preview part would be properly decoupled from the game itself.