Download

Assigning a room to an AI

This has been racking my head for a while now. I have achieved it in other ways but not to a standard I’m happy with.

I have 10 Room Blueprints, Each Room has a box collision inside of the room BP (as well as other things).

When spawning an AI I want it to check if a rooms are assigned and then bind that unassigned room to that AI.

When called I want the AI to return to to that room that has been assigned to it.

Any Assistance on this would be greatly appreciated.

May not be the best way But you could put a target actor in each room . Set it to be hidden in game.

Then just make you’re AI, move to the target location of the room you want the AI to go to .

Problem with this is, Upon the AI spawning I want each room they are bound to, to be random.

This way every time you play the game there will be a different AI in each room.

For Example

10 Rooms
AI Spawns and is assigned to a room then that room is removed from the array
This happens 10 times until all rooms are occupied.
When the AI dies that room is added to the array for a new AI to spawn at a set interval.

Array the target points, have the AI pick a random one, remove that index from the array. Repeat 9x.

that would work either I’m afraid, as the target points are outside the room so the room has to match up with the target point which is directly outside the door.

This would be simple if you could create a target point inside of the Room blueprint, that way you could just reference it like the room.

And you can’t create a target point inside of the Room blueprint because…?

I am going to assume that your rooms are static, meaning they are already built and represented in the game world.

  1. Plop a target actor in each room, each one gets a different Tag or name or however you want to identify it. As long as they are different from each other one.
  2. Have something omnipresent, like the Level blueprint, catalog all of the target actors in an array. Make the array accessible outside of the blueprint (eyeball).
  3. On constructed or begin play or whenever you want, in the AI, have it pull the array, get a random number between 0 and the length of the array, assign it that number.
  4. Pull the array information from that indexed random number, get the location, spawn there. Target point assigned.
  5. Either delete the target actor (sloppy method) or remove it from the index (cleaner method).
  6. Loop back to 3 the required number of times.

Generally that would be the flow of logic for what you are looking for.

If you build rooms at random locations, you can still spawn target actors in the room. Just get the room location and spawn a target actor in the middle of it. Then flow from step 2.

It wont let me insert a target point inside the Rooms BP, the option is just non existent.

Your method wont work, as I want the AI to be bound to the rooms Box collision (which I have already done) and the target point to be an extra event that the AI will move to upon being called.

So the room itself needs to be randomised not the target points.

Your rooms are randomised but you can still include a child actor in the middle of each of the rooms and then do exactly how Yggdrasil is talking about.

If he’s using blueprints he doesn’t even need to use target points I was only suggesting that to make things easy.
He could just have a int variable inside each room blueprint and assign this randomly .

Then assign this room number randomly to each ai. For each room number have a transform location of the matching room number he wants the AI to move to.

Eg room 1 give it a roomNumber int variable with a default value of 1.
AI spawns , AI number 6 is randomly assigned the room number 1.

Move AI 6 to room 1 transform location .

Just to clear up any confusion (specially my end :smiley: ) This High Tech drawing represents what I am after.

e6d8f63ffa0a48872749f5b2f433af6f9787f97f.png