Spawning an actor deferred may be what you are looking for. The normal method of spawning an actor, via UWorld::SpawnActor creates the actor and immediately initializes it, for example it calls BeginPlay() automatically. Spawning an actor deferred allows you to do dynamic stuff before the actor’s initialization is finalized. The way to do this:
- Spawn the actor with UWorld::SpawnActorDeferred()
- Do your dynamic initialization stuff here
- Call the spawn actor’s FinishSpawning function
Example code:
UWorld* World = GetWorld();
const FTransform SpawnLocAndRotation;
AMyActor* MyActor = World->SpawnActorDeferred<AMyActor>(AMyActor::StaticClass(), SpawnLocAndRotation);
MyActor->MySetupFunction( ... );
MyActor->FinishSpawning(SpawnLocAndRotation);
Now you’re certain your dynamic values are set in time before any replication.