Change Actor's Variables Before Spawning

For this I would usually use SpawnActorDeferred followed by FinishSpawningActor after setting the property values.


UWorld* World = GetWorld();
if( World )
{
	AMyActor* NewActor = World->SpawnActorDeferred<AMyActor>(
		MyActorClass, FTransform::Identity, nullptr, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);

	// initialize NewActor...

	UGameplayStatics::FinishSpawningActor(NewActor, SpawnTransform);
}

The actor isn’t actually constructed until the FinishSpawningActor call so don’t forget that part!

1 Like