How can I initialize actor properties when spawning?

I would like to spawn an actor that hands off some data to the constructor of this actor when spawned. How do I do that?

Usually I would plug in a FVector and FRotator after StaticClass(), how can I input some values I want the constructor of this actor to use?

AMyActor* theActor = World->SpawnActor(AMyActor::StaticClass() );

Hello, Thumper

Please note that there is a AActor* Template parameter in UWorld::SpawnActor function:

AActor* UWorld::SpawnActor
    UClass*         Class,
    FName           InName,
    FVector const*  Location,
    FRotator const* Rotation,
    AActor*         Template,
    bool            bNoCollisionFail,
    bool            bRemoteOwned,
    AActor*         Owner,
    APawn*          Instigator,
    bool            bNoFail,
    ULevel*         OverrideLevel,
    bool            bDeferConstruction

Template Actor is an AActor used as a template when spawning the new Actor. The spawned Actor will be initialized using the property values of the template one. If no template Actor is specified, the class default object (CDO) will be used to initialize the spawned Actor.

Hope this helped!


This is confusing for me. How am I to supply an actor to use as a template when I haven’t figured out the properties? In my case, I need to pass an array into the constructor of this actor class before the actor can spawn. The data in this array is generated just before I go to call the spawn of the actor. So how can I create a template actor?