Spawn an actor with a non default contructor

Hello,

I have my zero argument constructor ATable::ATable() and my 5 argument constructor ATable::ATable(float TableTopWidthVal, float TableTopLengthVal, float TableTopHeightVal, float LegHeightVal, float ChairsSpacingVal). How can I spawn my ATable with my 5 argument constructor? Can I use GetWorld()->SpawnActor() as well?

you don’t do it this way sadly, you have to spawn the actor deferred, here’s a code snipet:

UWorld* world = this->GetWorld();
AActor* ownerRef = nullptr;
FTransform Transform;
ATable* spawned = world->SpawnActorDeferred<Atable>(ATable::StaticClass(), Transform, ownerRef);
spawned->TableTopWidthVal = TableTopWidthVal;
spawned->TableTopLengthVal = TableTopLengthVal;
spawned->TableTopHeightVal = TableTopHeightVal;
spawned->LegHeightVal = LegHeightVal;
spawned->ChairsSpacingVal = ChairsSpacingVal;
spawned->FinishSpawning(Transform);

Here’s the general flow of the actor life cycle

On the left side of the flow chart you can see the spawn actor deferred function, I suspect when you use the “SpawnActor” node in blueprints and the actor has “expose on spawn” properties, then behind the scenes the engine uses the spawn actor deferred fuction