Two types API to modify Actor’s parameters before BeginPlay

1st way:

FTransform SpawnTransform(SpawnRot, SpawnLoc);
AMyCharacter* Character = world->SpawnActorDeferred<AMyCharacter>(ActorClass, SpawnTransform);
if (Character)
    Character->SetupFunction(... params ...);

2nd way:

FTransform SpawnTransform(SpawnRot, SpawnLoc);
AMyCharacter* Character = Cast<AMyCharacter>(UGameplayStatics::BeginDeferredActorSpawnFromClass(this, DeferredActorClass, SpawnTransform));
if (Character != nullptr)
    Character->SetupFunction(... params ...);
    UGameplayStatics::FinishSpawningActor(Character, SpawnTransform);

3rd way:

FActorSpawnParameters SpawnParameter;
SpawnParameter.OverrideLevel = GetLevel();
SpawnParameter.bDeferConstruction = true;    //it means BeginPlay() would be deferred, not constructor.
GetWorld()->SpawnActor<AMyActor>(ClassType, SpawnParameter);

These ways were verified in v4.21:

  • SpawnActor would trigger both Constructor and BeginPlay;
  • SpawnActorDeferred would trigger Constructor only;
  • BeginPlay would be triggered after FinishSpawning;
  • There’s no way to spawn actor before Constructor.

If there any other ways to pass arguments to the Constructor of Actor? An informal way is:
define static variables, set values of these variables before SpawnActor, then use these variables in the Constructor.