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 created?

My dilemma is that I created a spawn box that spawns my AI into the level, where normally you would place the AI character directly into the level 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 into the level and setting it’s initial waypoint, but that would mean I would need to remove my spawn box and it’s a pretty crucial piece to my game.

How are you spawning the AI in your game? Are you using SpawnActor? If so, you can specify the location that it spawns in. Note that it will not spawn if it will collide with something when spawned. Unreal Engine has this actor iterator available, I use it a lot to search my world for certain objects.

FVector spawnLoc;
for (TActorIterator<YouWayPointClass> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
    if (ActorItr->GetName() == "MySpecialWaypoint")
    {
        spawnLoc = ActorItr->GetActorLocation();
    }
}
    
	FActorSpawnParameters sp = FActorSpawnParameters(); //specify some parameters
	sp.Owner = NULL; //The owner of this spawned object
	sp.Instigator = NULL;
	sp.bNoFail = true;
	sp.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; //Spawn regardless of collision

	ACharacter * tmp = (ACharacter*)GetWorld()->SpawnActor(ACharacter::StaticClass(), &spawnLoc, &FRotator::ZeroRotator, sp);

That’s what I do, hope it helps.

P.S Sorry for the bad indentation, this sites code box is ruining my clean code.

Hey Aaron, yes I made a SpawnActor class and my AI characters spawn inside of the boxcomponent I attached to it. The problem isn’t the spawning, it’s once my AI characters spawn I want to set them to move to a waypoint I have already placed in the level. Normally you place the character in the level and set it’s waypoint location, but since they are spawned in I can’t do that.

How would I set an AI character to move to a waypoint in the world if he doesn’t exist yet?

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);
		}
	}
}

So is it not possible to set the desired waypoint for my ai character before he is spawned?