Picking tasks for AI characters advice

Behavior tree (assuming you are speaking about the BT assigned to each pawn) is per pawn. It has no information about any other pawns nearby. You could obviously GetAllActorsOfClass() and iterate, but that’s a bad solution IMO.

I’d simply store in the PlayerController ‘CurrentlySelectedPawns’ and choose from those. When the player clicks to make the building you handle that input through PC and then choose the worker, tell it to go there. Simplest solution I think. Use the BT for the actual moving only.

To make selecting using BT you would have to send player input there, calculate screen to world space (to determine which pawn was selected) and many other things you could much easily do in Player Controller. Not the way I’d go.

You can also use BT for something else than AI, but I suppose that’s not what you meant.

Hi!

Looking to get some advice from more advanced AI users, or whoever, about how to pick tasks for my AI Pawns to do. Here’s my scenario:

  • The level starts
  • 10 AI pawns are spawned, they’re added to an array of pawns
  • The player clicks a button and a house is spawned somewhere in the world

Okay I have all the above working, here’s where I’m looking for advice:

I need to select one of these pawns and have it run towards that building.

It’s the SELECTING of the pawn that I’m wondering if I need a behavior tree for. I can think of a way to just select the pawn WITHOUT a behavior tree: I can just run through my array of pawns, see if they’re doing a task, if they’re not, then pick that one. THEN run to the house via the behavior tree.

But I’m wondering if it’d be smart (for whatever reason, I’m not sure because I’m very new at AI) to have the SELECTING of the pawn be IN the behavior tree.

Anybody have any thoughts? Thank you so much!

Oh I see what you’re saying. Okay that makes sense.

What about the scenario of the player doesn’t have any pawns selected (and by design CAN’T have pawns selected). Meaning, this wouldn’t be an RTS type game, more like a simulation type game…where the pawns exist in the world and do tasks (like building or farming) based on whatever the player spawns (like a house or a plot of land for a farm).

Would you still have the same approach: Have a list/array of pawns in the world then when the player clicks to make the building you still handle their input through another BP (let’s say a pawnManager BP) and NOT through the behavior tree?

Just a quick second thought: I was wondering if an EQS service would be able to handle this sort of thing? Or if an EQS would just be overkill.

Thanks for your previous post and any other thoughts!

Hey derm,

Like vipeout said, you should run the selection through the controller. What I do for my selection process (usually with more than 1 type of actor I can select) I use an event dispatcher. In my main custom Player Controller, I add an event dispatcher, we’ll call it ‘SelectEvent’, and add an ‘Actor’ in it’s input.

Then, in my AI controller (or my Building BP or whatever else I want to be able to select) I get a reference to the main custom Player Controller in the Begin Play, and store this in a variable for later use. While in Begin Play, after I cast my Player Controller and save it, I Bind the ‘SelectEvent’ from my Player Controller. Then, create a custom event in the graph (of your desired selectable object) and we’ll call it ‘WasSelected’ with an input type of ‘Actor’, and use this custom function as the delegate to the Bind SelectEvent.

From there, in my ‘WasSelected’ event, I immediately pull off the ‘Actor’ pin, do == and compare it to “Self”. Branch off that conditional check, and if it’s True, then that instance of the object was selected and I’ll run my code according, whether that’s setting Blackboard Keys for my AI to select a Task, setting variables within the selected item, popping up a HUD or whatever it is I am trying to accomplish. If the == comes up False, I do nothing because it wasn’t the one selected.

Event Dispatchers are relatively expensive; however, if you have many types of objects you want to select in the world, it saves a headache over using Interfaces or other round-about ways of doing it so, to me, it’s worth the added cost.

To answer your other question, I would suggest this tutorial series: https://www.youtube.com/playlist?list=PLDnygpcOYwFW2XtNyiandrLDG__OAZs7Q

There’s currently 35 videos in the RTS/City Building type tutorial series and generally 2 new videos are added each week. It’s building a game from scratch with no steps done between videos - everything is done on camera. Several of the last videos were done doing AI tasks (construction process) doing exactly what you are asking for - A building is placed in the world and the NPC automatically knows where to go and what to do with no interaction from the player. The entire series is worth checking out, each video builds off of the last video, but conceptually, you can pick it up from anywhere and learn something new from it!

Nice, great advice. And awesome! Thank you for the video tutorials! I’ll definitely go through them and check them out.