Spawn Actor Deffered after construction.

I am creating the actors by calling construct object from a function called BeginPlay().

When I construct the actors I have some default properties set, these properties are set randomly, meanīng each time you construct them the outcome is different.

Once they are constructed and saved into an array. (they are not spawned yet). I carry out some tasks that rely on the random properties set by the objects constructor.

Then , when I am finished I want to spawn the actors into the world, how can I now spawn them without act of, re-constructing them?

heres the functions i used

then i used SpawnActorDeferred.
The problem is the actors constructor is still called and this changes the random properties.

I can make up two ways in my head:

  1. Create your actor hidden(HiddenInGame(true)) and then just call a function that unhides them when you want it.

  2. Don’t create a random actor, but rather create random properties (stored in a struct) and then when you want to spawn your actor, just pass it its properties struct.

There are, as always, other ways to achieve this.

Thanks but surely I shouldn’t have to do that. If I create the actors hidden then I run some checks on them and then re spawn as needed, its not very efficient having multiple copies of objects for nothing.
The properties are random, they are applied to the actor in the class constructor.

both of those ways seem cumbersome to me, I just want to spawn the actor that I already constructed why is that so difficult?

Anyway I made a function in the class constructor and kept a reference to the random properties, so I can set the properties after spawning.

Of course, but unreals default way of constructing Actors is by spawning them(You call World->SpawnActor() and the engine handles constructing it for you). So instead of preconstructing them, you should just normally spawn them in one way or the other and hide them until you need them. If you need them, you should not respawn them, but rather move them to the desired location and unhide them. Or the better way, just randomly generate Parameters(instead of actors) and store them in an array. On Spawn, just pass those values to the actor.

Afaik there is no way of constructing actors and then spawn them without having their constructor called, but I might be wrong on this.

You are correct, I have not found a way to spawn them without having their constructor called. I did exactly what you said I construct them and save them in an array while also saving a ref to the properties, then I carry out the tasks i needed on the properties and when I need to spawn then I spawnActor and copy the properties from the first array into the new object and then call setProperties() to reset them back to the first type.