# How Can I Set Hostile in AI Preception?

**URL:** <https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954>\
**Category:** Community & Industry Discussion\
**Tags:** unreal-engine, enemy, question\
**Created:** [July 20, 2015, 11:38pm UTC](https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954 "2015-07-20T23:38:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_0972e5c0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0972e5c0](https://forums.unrealengine.com/u/anonymous_user_0972e5c0)\
**Post date:** [July 20, 2015, 11:38pm UTC](https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954/1 "2015-07-20T23:38:09Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_dceb25d5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_dceb25d5](https://forums.unrealengine.com/u/anonymous_user_dceb25d5)\
**Post date:** [May 23, 2017, 5:18pm UTC](https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954/2 "2017-05-23T17:18:11Z")

</div>

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…

> **[AI Perception in Unreal Engine 4 – How to Setup](https://denisrizov.com/2017/05/08/ai-perception-in-unreal-engine-4-how-to-setup/)**
>
> For those of you who are wondering what AI Perception is – this is a really nice system in UE4 that provides an easy way for the enemy AI in your game to track hostile/friendly/neutral charac…

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

---

<div class="post-metadata">

**Author:** ![SolSweet13](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/solsweet13/32/719817_2.png) [@SolSweet13](https://forums.unrealengine.com/u/SolSweet13)\
**Post date:** [September 22, 2021, 11:57pm UTC](https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954/3 "2021-09-22T23:57:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![WiLLYB0YW0NKAtm](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WiLLYB0YW0NKAtm](https://forums.unrealengine.com/u/WiLLYB0YW0NKAtm)\
**Post date:** [May 12, 2025, 2:23pm UTC](https://forums.unrealengine.com/t/how-can-i-set-hostile-in-ai-preception/325954/4 "2025-05-12T14:23:57Z")

</div>

You need to do it in C++. Here’s how you would do it If you want to use the default Enemy, Neutral, or Friendly team system unreal has already implemented.

1. In your player class, inherit from IGenericTeamAgentInterface

//The two includes below are only recognized if you add “AIModule” to your build.cs list  
// PublicDependencyModuleNames.AddRange(new string { “Core”, “CoreUObject”, “Engine”,  
// “InputCore”, “EnhancedInput”, “AIModule” });

#include “Perception/AIPerceptionTypes.h”  
#include “GenericTeamAgentInterface.h”

class AYourCharacer : public ACharacter, public IGenericTeamAgentInterface

1. Override this function  
virtual FGenericTeamId GetGenericTeamId() const override;

2. Create a TeamID UProperty

UPROPERTY(EditDefaultsOnly, Category = “AI”)  
uint8 TeamID;

1. Define the overridden function in cpp to return TeamID

FGenericTeamId AYourCharacter::GetGenericTeamId() const  
{  
return FGenericTeamId(TeamID);  
}

That’s it! Keep in mind Pawns, AIControllers, and anything that has the AIPerceptionStimuliSource component will be defaulted to neutral.
