Let’s say I have a BehaviorTree and some NPCs controlled by such tree through an AIController. I want the behavior for all NPCs to be exactly the same, for example, they all need to patrol, wait, patrol some more, etc, but with slightly different parameters, for example, a dfferent list of points for each NPC to patrol.
I think I’m missing something pretty obvious here because I can only imagine that’s a common request, but I can’t find a clean way to do it. I know I can, for example, have a variable in each NPC with the path to patrol and then set it on the blackboard, but IMO that’s creating coupling and breaking the single responsibility principle.
I’d like AI, it’s logic and parameters to be all inside the AIController, BehaviorTree and Tasks. On the other hand, I can’t find a way to pass parameters to them, and the only possible solution I see is to have a different AIController for each instance of NPC, despite their behavior being exactly the same.
Does anyone have a good suggestion on how to approach this?
You actually have the right idea. Make the points variables, make them public, and as you place the actors in the scene, specify nodes to walk to in the details panel of the level designer. Then in the AI controller get them from the owning character and input them into the blackboard.
You see, it doesn’t violate the single responsibility principle because these are all instances. Each instance of a character has their own instance of the BehaviorTree, Blackboard, and nodes to walk to.
Thank you for the response @Mind-Brain! Your solution sounds doable and straightforward (and I believe it’s what I will end up doing), but I think it still violates the separation of concerns I was trying to achieve.
Ideally I’d like to keep AI related variables (for example the patrol points) in the respective tasks (or blackboard) they belong to. By adding these variables to the actor (even with the single purpose of later copying them to the blackboard), the pawn becomes coupled to the AI behavior, while ideally I believe they should be separated.
Oh the other hand, I still see no other way of doing it, since we can only specify the AIController class for a pawn in the details panel, but we can’t configure any of its variables. And even if I do create a unique AIController class for each single NPC and enemy in the game (which is not really practical), I still wouldn’t be able to reference actors in the level (like the patrol points)
I think you can create variables in your pawn class and pass it in blackboard so each AI character you place in level you can specify they variables (public and instance edit)