Assigning houses to AI

Hello guys!

I’ve been developing a system in which a house detects an AI via an overlap of a collision box and then sets the number of occupants of the house.

I’ve created tasks and services in a behaviour tree so that an AI can check whether the house is free or empty. I’ve got the code working, however the Master BP the child House BP’s work of seem to not be detecting the NPC’s correctly. When I place the houses down the all the NPC’s just go to the first house, seemingly not detecting the current occupants.

I’m a little stuck with this and all sorts of rewiring and rewriting of the script isnt working, so I was hoping someone would be able to give me some tips on how to do this!

Thanks!!!

To be more clear, I’m trying to develop a system similar to RCT 2/3 where NPC are randomly generated and walk into the play space where the AI begins looking for things to do.

The first thing on the AI’s list of things to do is to find a house. Right now each house only is set for 1 NPC.

I’m looking for help in developing a script which scrapes all the houses currently built, to check whether there is enough room and whether its occupied. If a house has enough space and isnt occupied sent the NPC there and assign it to them.

Right now the script I’ve created isnt working and driving me up the wall tbh. If I could get some help with this I would be extremely grateful, and hopefully help others with their projects too! Thanks!

Hey, thanks for the reply!

Actually no… the as I’ve set it up now the max occupants / current occupants is detected by a collision volume. So when an AI goes to the house only then is the number of current occupants updated.

this is the behaviour tree btw…

So, when a house get placed this notifies the spawning system that its ok to spawn another AI actor. So if you spawned houses very fast it would happen simultaneously for multiple AI characters.

Hi, the code in your image looks fine. You directly increase the number of occupants as soon as the AI choose the house and not just once it reaches it, right?

Generally speaking you can do prints to see what is going on and where it fails (e. g. print CurrentOccupants and see if it is always 0). If you also use blackboards then you can also use the AI debugger to see the values of the blackboard.

Actually no… the as I’ve set it up
now the max occupants / current
occupants is detected by a collision
volume. So when an AI goes to the
house only then is the number of
current occupants updated.

Ok, then one AI chooses a house → walks up to it → update house occupants, then the next AI chooses a house walks up to it… and so on until all AI have found a house? So you wait for each AI to reach its choosen house before proceeding to choose a house for the next AI?

Then you logic should fail, no? Cause you only register a new occupant once the AI reaches the house. So if you spawn e. g. another 10 AI before that, they will choose the same house since it still registers empty…

So really there should never be more guests spawned than houses available.

and sorry its not houses its rooms.

Forgot I changed that!

After A LOT of debugging I’ve got the behaviour I want! Thanks for the help @ chrudimer. I do however have a bug where if I place buildings down super quick this will result some of the logic breaking. This will either cause two npc’s going to the same room or one less npc spawning than should.

So I need to develop a different way of detecting the occupants instead of a collision volume?

Hmmm might be something to that now looking back at the code.