Friendly / Non friendly creature Ai Workflow Questions

Hey, Im having a hard time Wrapping my head around communicating information from Instances of Enemies to Behavior trees. and im also having a hard time figuring out
an efficient system for making a bunch of different enemies.

At the end of the day i need to make a 30 or so creatures that can be friendly or Feral. and have a bunch of other either shared or specific variables to that character.

In searching around, classes came up and im pretty foggy on the subject, usually with casting i can get by okay but its a lot of fiddling because i dont 100% understand when to use what.
(PawnOwner, Player Controller, etc.)
Rescources i have found on Ai and enemies have only dealt with one character using its own simple behavior tree so Im curious of conventions i should implement in doing this over a bunch of characters.
and just to clarify im not set on using just one behavior tree for everything and everyone. just sharing one for the most basic of AI actions.

  • Would the solution be having all of the NPCs in the same class and casting to that class in the AI Controller?
  • From that cast how would I get particular variables from particular class members?
  • Do i need to make a chain checking if the Instance of the creature is Vaild?

So as is the plan is ( All PC pawns -> Ai Controller -> Behavior tree )

I tried:

NPC (Begin Play) Cast to AI_Controller -> Set Friendly?

AI_Controller (Begin Play) Run Behavior Tree -> (Blackboard) Set Value as Bool(Friendly?)

But Unreal got angry. it gave me an error because it wasnt reading it properly.

I was planning on keeping the information im trying to pass on as booleans representing states or sometimes behaviors ie. Is friendly? will attack on sight?
But i also have a RNG during idle roaming deciding whether to pick a new location or play an idle animation which are represented by
an integer value.

Im sorry if this is a little confusing - This question is the byproduct of mass confusion lol

*** EDIT ***

I tried setting blackboard values from the NPC and skipped the AI controller and it worked so thats where im at now

Hi. For my own project I made different classes for different types of enemies (Enemy_melee, Enemy_ranged, Enemy_nonhuman) deriving from common enemy_base class, each of them has their own AiController class (so separate ai_melee, ai_ranged and ai_nonhuman), behavior trees and blackboards. Friend-or-foe behavior is handled in the controller (I’m using ai perception component in the controller, so all “detection” is done there), by checking TeamID variable of the detected actor - if it’s the same, then do nothing, if not - send an “attack” signal to blackboard (in my case it is Blackboard - Set Value as Enum (KeyName=“GuardState”, Enum=“Attack”) and then behavior tree get’s it from here and continues within itself.

Hey Thanks so much for the reply! that definitely helps out a lot.

I’ve been working on this for a little while now and I’ve figured out a decent communication flow
If this helps anyone in a similar situation this is what im doing;

Any Npc ->Behavior tree -> Ai Controller -> Acting Pawns AnimBP -> Specific Actor

Variables are color coded*

I’ll use idle events as context.

All NPCs have the same 2 integer variables to handle Idle States: Total Idle Animations, Current Idle Animation.

  • Upon creation the instance of the npc sends TOTAL IDLE ANIMATIONS to the blackboard / Behavior tree.

Behavior Tree (Wander Sequence)

  • Find Location with 5m and move to it. On completion do a dice roll ‘Set Is in Idle(B)’ with result

  • If no (0) - wait 5 seconds - end

  • if yes (1) - Use sum of Total idle animations as max for rng roll

  • Cast RNG result to AI_Controller through a custom event (Enter Idle) with integer in/out

to the AI controller

  • “Enter idle” custom event is triggered. Set Idle Event # as RNG result

to The Anim BP

(event update) Casting to AI_Controller - Get Idle Event#

  • Set AnimBP Idle Event #
  • Idle Event # X triggers Animation play
  • X animation ending triggers Notify event
  • Notify event casts to NPC Triggering Custom Event (End Idle)

In the NPC BP

“End Idle” Custom Event Sets Blackboard Value "Is In Idle(B)’ (0)

  • End

Using this system you avoid doing any specific actor casts allowing you to just plug and play different NPCs. you would just need to send a bunch of variables about the character to the master behavior tree to control different sequence decorators etc.

Character type - Is a bird, is a bear, is a frog,
Can Shoot Projectiles?
Will attack on sight?
Team A / Team B ( SHOUT OUT TO MY BOI ^)

I think this works well for people in my situation to cut out a lot of reproduction and giving a decent baseline to add and grow their enemy or npc system.
and in more specific situations you could just have character specific events trigger Character Specific or Situation Specific Trees

I hope this helps somebody!
If you can think of a better way of implementation or this is total lunacy please let me know. Im still really new to coding and unreal!