Spawn actor after construction

I have an array of actors that are already constructed, there is some code in the constructor that is random.

In another class I can spawn them fine, but the constructor is called again which is not what I want.

so how can I spawn the actors that already exist.

First of all you should avoid using constructor for spawning Actors and any world interaction, class constructor is called when things are not initiated and also called on engine start to get defaults, you should do start code in BeginPlay() called when actor (including gamemode as gamemode is also actor) is ready to go and in constructor place default values of properties (class constractor in UE4 is like defaultpropeties in UnrealScript).

Now you should “construct” Actors by spawning them, ()->SpawnActor(…) return pointer to Actor to newly spawn actor, so you could spawn actors you want in BeginPlay() and put there pointers in array. Main reason why you need to that this way is because UE4 object system

If you trying to do inventory system with actors, you should spawn them anyway and disable components to hide it from the world and later put them back to make actor back being physical then needed

Even thru UnrealScript is gone, C++ APIs is mostly the same as in UnrealScript and best practice in UnrealScript works (not compliantly but still) in C++ APIs of engine

Thanks for the answer, I am not spawning actors in the constructor, that’s not what I said, I don’t think you understood the question.

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?

This seems like a basic thing, i’ve searched api but not found anytthing.

Then why dont you spawn them right away so actor constractor is called once?

Well I think I solved my problem, by setting the properties after spawning, but its not really a good solution.
I would like the ability to spawn already existing objects.

Because then they are rendered on the screen, and I don’t want to render them until I have decided if they have the correct properties add to this the fact that the act of re-spawning them recalls the constructor. This makes it a problem.

Then hide/disable the physical components?

You are aware that actors are made out of components? You can hide them so they are not visible. In old UEs inventory system (which does not exist anymore used single actor object as inventory item and item in world

yes I created the actor its my own class, I also added the components, but I also need to set the properties of the components and it gets cumbersome to cast and recast the Object and hide/unhide.

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.

Im probably not explaining it very well, I can’t hide them because I need to create 100’s of objects and then when the random properties are the correct configuration I will spawn, that is why I don’t want to spawn and hide as the performance is not good.