How Can I Set Hostile in AI Preception?

I am trying to get my UFO’s AI perception to recognize the player as hostile, but I can’t seem to figure out where I can set it. (I’ve already set my UFO’s Detect by Affiliation to Detect Enemies only).

Even after 2 years this is still not very clear on how to do in BluePrints. How do I set my character or another pawn to be on a different team like hostile? i found this guide…

but it says it can only be done in code, is this still correct?

I’ll try my best to explain using the perception system and having it “know” about hostile actors, at least my understanding of it; I’m using UE 4.27.

  • The Pawn class has a reference to a Controller class.
  • The Controller class has a reference to the Perception Component.
  • The Controller also has to have the Generic Team Id implemented | The AAIController already uses this, but the APlayerController doesn’t (you’d have to implement the IGenericTeamAgentInterface in C++)
  • This also means creating a variable to track the GenericTeamId (I wasn’t able to find a way to add this to either the AI or player controller outside of C++)

The issue I found to happen was the Perception Component, when processing the Stimuli was passing in the result of GetOwner() [Which is a controller class] and the Actor that was perceived [Which was a Pawn] to the GetTeamAffiliation() function which took actors for parameters; to me this indicated that the function was passing in a pawn and controller but only the controller was using the Generic Team Id setup.

So looking at this problem of comparing Controllers and Pawns, I see 2 easy ways to fix the problem:

  1. I can look to edit the engine’s code so that when processing the stimuli the function checks to see if the perceived actor is a Pawn and if so get the controller for it and run the affiliation test against that. But currently I’m hesitant to change editor code. Or…
  2. Implement the IGenericTeamAgentInterface on the Pawns and have their Team Ids match or reference their own controller.

That way when the Perception code runs the check from the Controller’s team id against the Pawn’s team id, the Pawn can also return it’s Generic Team Id. I’m made the #2 change and tested it, and now I am able to get a list of hostile actors from the blueprint function. Unfortunately the fix needed to be done in C++ code.

1 Like