Download

Is it possible to initialize an AI character's to a waypoint before it's created?

I’m wondering if it’s possible to initialize an AI character to move to a waypoint before it is spawned into the world?

My dilemma is that I created a Spawner that spawns my AI into the world; where normally you would place the AI character directly into the world and give it a variable and then set the variable to the waypoint. Unfortunately since my AI doesn’t exist until after the editor has begun playing I can’t set it’s waypoint.

How would I circumvent this? I’m using a mix of C++ and blueprints and any help with either would be greatly appreciated.

I’ve been combing the forums, looked for videos or tutorials and can’t find a solution. All I’ve found for AI characters and waypoints is the character being placed in world and setting it’s initial waypoint, but that would mean I would need to remove my spawner and it’s a pretty crucial piece to my game.

This is my SpawnEnemy constructor in my SpawnActor class:


void ASpawnPoint::SpawnEnemy()
 {
     /// If we have set something to spawn
     if (WhatToSpawn != NULL)
     {
         // Check for a valid World
         UWorld* const World = GetWorld();
         if (World)
         {
             // Set the spawn parameters
             FActorSpawnParameters SpawnParams;
             SpawnParams.Owner = this;
             SpawnParams.Instigator = Instigator;
 
             // Get a random location to spawn at
             FVector SpawnLocation = GetRandomPointInVolume();
 
             // Get a random rotation for the spawned item
             FRotator SpawnRotation;
             SpawnRotation.Yaw = 0.0f;
             SpawnRotation.Pitch = 0.0f;
             SpawnRotation.Roll = 0.0f;
 
             // Spawn the enemy
             AEnemy* const SpawnedEnemy = World->SpawnActor<AEnemy>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
 
             SpawnDelay = FMath::FRandRange(SpawnDelayRangeLow, SpawnDelayRangeHigh);
             GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnPoint::SpawnEnemy, SpawnDelay, false);
         }
     }
 }

Use spawnactordeferred.

create a management class? I am making an arena style level, in it I have an actor that manages spawning enemies and setting their routes if needed. You do a struct and hold a ref to the spawnpoint and an array of the route nodes.