Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.alt text

Product Version: UE 4.20
original-spawn.png (176.1 kB)
newspawn.png (120.5 kB)
more ▼

asked Mar 16 '19 at 09:17 PM in VR

avatar image

18 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

Spawn Random Actors

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!


more ▼

answered Mar 17 '19 at 01:38 AM

avatar image

179 3 9 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question