Advertisement
orfeasel

Actor Spawning

Feb 22nd, 2016
22,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. void AActorSpawner::BeginPlay()
  2. {
  3.     Super::BeginPlay();
  4.  
  5.     FTimerHandle OutHandle;
  6.  
  7.     //Will call SpawnUsefulActor after the specified time
  8.     GetWorld()->GetTimerManager().SetTimer(OutHandle, this, &AActorSpawner::SpawnUsefulActor, TimeToSpawn);
  9.    
  10. }
  11. void AActorSpawner::SpawnUsefulActor()
  12. {
  13.     //If the usefulactorbp is valid
  14.     if(UsefulActorBP)
  15.     {
  16.         //Spawn parameters for the current spawn.
  17.         //We can use this for a number of options like disable collision or adjust the spawn position
  18.         //if a collision is happening in the spawn point etc..
  19.         FActorSpawnParameters SpawnParams;
  20.  
  21.         //Actual Spawn. The following function returns a reference to the spawned actor
  22.         AUsefulActor* ActorRef = GetWorld()->SpawnActor<AUsefulActor>(UsefulActorBP, GetTransform(), SpawnParams);
  23.  
  24.         GLog->Log("Spawned the UsefulActor.");
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement