Randomly Spawn and AI using Tags

I currently have a spawner working where I am using a Box Collision that spawns an AI in a spawn area (box collision). This works fine with the one AI I have spawning in a random location designated by the boxes parameters. See OriginalSpawn screenshot.

Now that I have 2 different AI’s in the game (and would like to add more), I would like to choose a random AI to spawn when I enter the box trigger.

I have tried ‘Get All Actors from Class’ but was not successful. I then set tags for my AI and tried to use ‘Get All Actors with Tag’ as you can see in the second screenshot. This does not see to be working. See NewSpawn screenshot.

Any suggestions would be greatly appreciated.

Hi FireBolt4964,

The functions ‘Get All Actors from Class’ and ‘Get All Actors with Tag’ look for actors within your level. I assume there are no AI actors in your level at start so that’s why these functions return nothing.

A better way to achieve what you want is to create an array of AI classes.
Now, to spawn a random AI actor, you just have to pick a random element from your class array and spawn an actor of that class, like so:

Note that in my case ‘ClassArray’ is an array of AActor classes, but you’ll probably want to create an array of your base AI class.

Hope it helps!

Cheers.