UWorld::SpawnActor

Spawn Actors with given transform and SpawnParameters

Windows
MacOS
Linux

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

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback