UWorld::SpawnActor

Syntax

AActor * SpawnActor
(
    UClass * InClass,
    FVector const * Location,
    FRotator const * Rotation,
    const FActorSpawnParameters & SpawnParameters
)

Remarks

Spawn Actors with given transform and SpawnParameters

Returns

Actor that just spawned

Parameters

Parameter

Description

Class

Class to Spawn

Location

Location To Spawn

Rotation

Rotation To Spawn

SpawnParameters

Spawn Parameters

Example Code

MySpawner.cpp at line 17:

void AMySpawner::Tick(float DeltaTime)  
{  
    Super::Tick(DeltaTime); // Call parent class tick function  

    if (Iteration > 0)  
    {  
        TimeToSpawn -= DeltaTime;  
        if (TimeToSpawn < 0.f)  
        {  
            // Make a location for the new actor to spawn at (300 units above this actor)  
            FVector NewLocation = GetActorLocation() + FVector(0.f, 0.f, 300.f);  

            // Spawn the new actor (Using GetClass() instead of AMySpawner so that if someone derives a new class  
            // from AMySpawner we spawn an instance of that class instead)  
            AMySpawner* NewActor = GetWorld()->SpawnActor<AMySpawner>(GetClass(), NewLocation, FRotator::ZeroRotator);  

            // Housekeeping so that we dont spawn new actors forever  
            NewActor->Iteration = Iteration - 1;  
            Iteration = 0; // stop ourselves spawning any more  
        }  
    }  

}

References

Module

Engine

Header

Runtime/Engine/Classes/Engine/World.h

Source

Runtime/Engine/Private/LevelActor.cpp