Severe CPU Choking on Spawn Actor

G’day chaps!

So, I’ve traced my spawn logic’s CPU choke to this set of lines here. And when it finishes the spawning process (even with my rather lightweight begin play functionality tied to the buildable actor disabled), my CPU tanks the frame at a whopping 300ms. Not sure if there’s a way to async this better or have it run the spawn logic with soft refs or something, but I’ve found this very odd as my non-deferred SpawnActor() calls have seemed to be a lot cheaper (e.g. spawning an ai, which seems like it would be more expensive all things considered).

ABuildableActor* NewActor = GetWorld()->SpawnActorDeferred(ActorClass, SpawnTransform);
NewActor->OccupiedTiles = Tiles;
NewActor->MarginTiles = MarginTiles;
NewActor->PlacementOrigin = Origin;NewActor->PlacementRotation = Rotation;
NewActor->FinishSpawning(SpawnTransform);

Thoughts or answers on this are much appreciated! Thank you!

Hey there @MiscellaneousMyth! Interesting! Like you I would have believed that the deferred spawning and preprocessing of your procedural generation logic would have been better.

How does it play if you do the generation actions after the spawning of the object? Does the spike occur even with small amounts of Tiles? Is the spike linear?

Depending on these answers, it might be necessary to async load the resources first, then feather out the actual spawning of the tiles over multiple game ticks.

Hey! Thanks for the reply @SupportiveEntity!

No, it doesn’t seem to scale off of the tile count, I’ve boiled the hitch down to the FinishSpawning line. If I break it right before that point it doesn’t hitch and if I break it the line after it chokes (and to reiterate, the begin play logic and constructor logic are all disabled within the ABuildableActor, so this should just be raw spawning cost).