# How do I use the AI Perception Teams?

**URL:** <https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [January 8, 2019, 3:58am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837 "2019-01-08T03:58:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 8, 2019, 3:58am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/1 "2019-01-08T03:58:01Z")

</div>

I’m trying to implement AI Perception in C++ and I got to the point I always get stuck with and do workaround, the teams or affiliation (friendly, neutral, enemy). How do I assign different teams to different controllers? I know this was asked before, but I can’t really understand how to do it, and some stuff is outdated. The AI Controller already implements the GenericTeamAgentInterface, so what would be my next step from here? Sorry if it’s super clear and I’m missing it, I come from Blueprints and all I know of C++ is from experimenting in the engine. Thanks for your time \<3

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 10, 2019, 10:54am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/2 "2019-01-10T10:54:28Z")

</div>

Hi Rainbow!

Don’t feel bad about been confused by this system, it’s a bit of a learning cliff. I had to read through quite a lot of code in order to figure it out.

The ordering of this might be a little off, because I’m working on memory that’s a little old.

First up, we need to define the Teams. I found the best way was to create a new UENUM:

```auto

UENUM(BlueprintType)
enum class EGameTeam : uint8
{
    Neutral,//Everyone ignores this team
    Team1,
    Team2,
    Team3,
    Team4 //etc...
};

```

Second, we need to define the Attitude of each team, towards each other team,

I made a Struct that contains an Array of ETeamAttitudes. Putting this struct as the Element of another Array gives us an entry for each team’s attitude towards all the other teams.

**Important** : Unreal’s Serializer does not understand “Array of Arrays”. Hence, putting it in the structure.

```auto

USTRUCT(BlueprintType)
struct FTeamAttitude
{
    GENERATED_BODY()
public:
    UPROPERTY(BlueprintReadWrite, EditAnywhere)
        TArray<TEnumAsByte<ETeamAttitude::Type>> Attitude;

    FTeamAttitude() {};

    FTeamAttitude(std::initializer_list<TEnumAsByte<ETeamAttitude::Type>> attitudes):
        Attitude(std::move(attitudes))
    { };
};

```

Now, here’s the tricky bit: Where do we put this Array? AND, how do we tell the Perception System to use it?

We need to tell it to use a custom **AttitudeSolver** , which tells it the \*\*ETeamAttitude \*\*of each of your Teams towards the others. We tell it with this function:

```auto

void FGenericTeamId::SetAttitudeSolver(FGenericTeamId::FAttitudeSolverFunction* Solver)

```

Note that this function is **static** and **doesn’t** accept a delegate, it expects a raw function pointer. That function signature looks like this:

```auto

ETeamAttitude::Type AnAttitudeSolver(FGenericTeamId A, FGenericTeamId B)

```

So, we need a place to store our Attitude Data (in Serializer friendly way) that can be accessed **globally.** And of course in Editor. Yuck.

The feature I found that is a good solution to this is extending the \*\*UDeveloperSettings \*\*class. Correctly setup, this will give your game it’s own settings menu in the Project Settings. I suggest something along the lines of this as a starting point:

```auto

#pragma once

#include "CoreMinimal.h"
#include "Engine/DeveloperSettings.h"
#include "TeamAttitude.h" //Our creation
#include "GenericTeamAgentInterface.h"
#include "MyGameSettings.generated.h"

UCLASS(Config = Game, DefaultConfig)
class UMyGameSettings : public UDeveloperSettings
{
    GENERATED_BODY()
public:

    UPROPERTY(Category = "Artificial Intelligence", EditAnywhere, BlueprintReadOnly, Config)
        TArray<FTeamAttitude> TeamAttitudes;

public:

    UMyGameSettings(const FObjectInitializer& ObjectInitializer);

    static const UMyGameSettings* Get();

    UFUNCTION(Category = "Artificial Intelligence", BlueprintPure)
        static ETeamAttitude::Type GetAttitude(FGenericTeamId Of, FGenericTeamId Towards);
};

```

This is where the magic happens. Notice those static function declarations? Also an important note here is that the \*\*UMyGameSettings \*\*class is setup as a **Config**. When you modify these later on, they will be stored in your DefaultGame.ini file.

It’s implementation is going to look something like this:

```auto

#include "MyGameSettings.h"

UMyGameSettings::UMyGameSettings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
    typedef ETeamAttitude::Type EA;
    TeamAttitudes = {
        {EA::Friendly, EA::Neutral, EA::Neutral, EA::Neutral, EA::Neutral },//Neutral
        {EA::Neutral, EA::Friendly, EA::Hostile, EA::Friendly, EA::Hostile},//Team1
        {EA::Neutral, EA::Hostile, EA::Friendly, EA::Hostile, EA::Hostile},//Team2
        {EA::Neutral, EA::Friendly, EA::Hostile, EA::Friendly, EA::Friendly },//Team3
        {EA::Neutral, EA::Hostile, EA::Hostile, EA::Friendly, EA::Friendly }//Team4
    };
}

const UMyGameSettings* UMyGameSettings::Get()
{
    return GetDefault<UMyGameSettings>();
}

ETeamAttitude::Type UMyGameSettings::GetAttitude(FGenericTeamId Of, FGenericTeamId Towards)
{
    auto & teamAttitudes = UMyGameSettings::Get()->TeamAttitudes;
    bool ofValid = teamAttitudes.IsValidIndex(Of.GetId());
    bool towardsValid = teamAttitudes.IsValidIndex(Towards.GetId());

    if (ofValid && towardsValid)
    {
        auto & attitudes = teamAttitudes[Of.GetId()].Attitude;
        if (attitudes.IsValidIndex(Towards.GetId()))
        {
            return attitudes[Towards.GetId()];
        }
    }
    return ETeamAttitude::Neutral;
}

```

Now, because of the static declarations, we can access **UMyGameSettings::Get** and **UMyGameSettings::GetAttitude** from anywhere! The \*\*UMyGameSettings \*\*class uses a feature in Unreal, where all classes have a “default” constructed for them at load time. This default object is loaded up with our configured Team Attitudes, which we can also tinker with in the Project Settings. Nice!

Now we tell the Perception System to start using it! The logical place I found to do this is to override either **AGameModeBase::StartPlay** or **AGameModeBase::InitGame.**

```auto

void AMyGameMode::StartPlay()
{
    //Setup our teams detection
    FGenericTeamId::SetAttitudeSolver(&UMyGameSettings::GetAttitude);
    OnStartPlay();
}

```

Here, we are giving that pesky static function our statically defined GetAttitude function. (Which we made blueprint accessible, because we aren’t monsters like they who designed this).

Phew! That’s a lot of text. I’m sorry if I’ve made mistakes in the code, I had to strip some stuff out of it.

I’ll post up what you need to do to your Actors / Controllers in another post. After I’ve grabbed a cuppa.

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 10, 2019, 11:39am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/3 "2019-01-10T11:39:58Z")

</div>

Onto the thankfully less meaty AI Controllers and Pawns.

There’s two key things to learn here:

A **PerceptionComponent** must be on an **AIController** to work. **AIController** already inherits from **IGenericTeamAgentInterface** , but the value it returns is private, both in Blueprint and C++, AND isn’t recognized in the Reflection System. Huh…

An \*\*AIPerceptionStimuliSource \*\*needs to be on the actual **Source** Actor, which must implement the **IGenericTeamAgentInterface** in order for the _Attitude Solver_ to return an Attitude that isn’t just _ **Neutral** _.

So to get this working fully, we’ll want to Implement the \*\*IGenericTeamAgentInterface \*\*on an \*\*AAIController \*\*child class, and on any **AActor** that will have an \*\*AIPerceptionStimuliSource, \*\*returning what we want instead:

```auto

UCLASS()
class AMyAIController : public AAIController
{
    GENERATED_BODY()
public:

    UPROPERTY(Category = "Artificial Intelligence", BlueprintReadWrite, EditAnywhere)
        EGameTeam AITeamID;

public:/**IGenericTeamAgentInterface*/

    virtual void SetGenericTeamId(const FGenericTeamId& InTeamID) override;
    virtual FGenericTeamId GetGenericTeamId() const override;
};

```

```auto

void AMyAIController::SetGenericTeamId(const FGenericTeamId & InTeamID)
{
    AITeamID = (EGameTeam)InTeamID.GetId();
}

FGenericTeamId AMyAIController::GetGenericTeamId() const
{
    return uint8(AITeamID);
}

```

The only change to the above code for a Regular \*\*AActor \*\*class, would be to add in “, public **IGenericTeamAgentInterface** ” after “public **AActor** ”

Now, we should be done. I’ve probably forgotten something, so let me know how you go!

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 11, 2019, 8:07pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/4 "2019-01-11T20:07:08Z")

</div>

Thanks for the answer, I’ll try to implement everything on my side and come back here if I run into any other problems

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 12, 2019, 2:41am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/5 "2019-01-12T02:41:08Z")

</div>

I may be missing something here, where would the UENUM and USTRUCT go? Should I use an empty class to hold them?

Update: I used an empty class, though the GetAttitude function is being a bit problematic on compile:

```auto

Settings.cpp(23) : error C2440: 'initializing': cannot convert from 'const TArray<FTeamAttitude,FDefaultAllocator>' to 'TArray<FTeamAttitude,FDefaultAllocator> &'
Settings.cpp(23): note: Conversion loses qualifiers
Settings.cpp(29) : error C2440: 'initializing': cannot convert from 'TArray<TEnumAsByte<ETeamAttitude::Type>,FDefaultAllocator>' to 'FTeamAttitude &'
Settings.cpp(30) : error C2039: 'IsValidIndex': is not a member of 'FTeamAttitude'
Custom.h(34): note: see declaration of 'FTeamAttitude'
Settings.cpp(32) : error C2676: binary '': 'FTeamAttitude' does not define this operator or a conversion to a type acceptable to the predefined operator

```

If I change

```auto

TArray<FTeamAttitude> & teamAttitudes = UPsychiatrixSettings::Get()->TeamAttitudes;

```

to

```auto

TArray<FTeamAttitude> teamAttitudes = UPsychiatrixSettings::Get()->TeamAttitudes;

```

I get:

```auto

Settings.cpp(29) : error C2440: 'initializing': cannot convert from 'TArray<TEnumAsByte<ETeamAttitude::Type>,FDefaultAllocator>' to 'FTeamAttitude &'
Settings.cpp(30) : error C2039: 'IsValidIndex': is not a member of 'FTeamAttitude'
Custom.h(34): note: see declaration of 'FTeamAttitude'
Settings.cpp(32) : error C2676: binary '': 'FTeamAttitude' does not define this operator or a conversion to a type acceptable to the predefined operator

```

I have a feeling I’m missing something here.

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 12, 2019, 6:09am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/6 "2019-01-12T06:09:36Z")

</div>

Ahh yes sorry I goofed a little during my cleanup. Add a const qualifier in front:

```auto

const TArray<FTeamAttitude> & teamAttitudes = UPsychiatrixSettings::Get()->TeamAttitudes;

```

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 12, 2019, 6:40pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/7 "2019-01-12T18:40:53Z")

</div>

That one’s fixed now. The remaining errors are:

```auto

Settings.cpp(29) : error C2440: 'initializing': cannot convert from 'TArray<TEnumAsByte<ETeamAttitude::Type>,FDefaultAllocator>' to 'FTeamAttitude &'
Settings.cpp(30) : error C2039: 'IsValidIndex': is not a member of 'FTeamAttitude'
Custom.h(34): note: see declaration of 'FTeamAttitude'
Settings.cpp(32) : error C2676: binary '': 'FTeamAttitude' does not define this operator or a conversion to a type acceptable to the predefined operator 

```

The offending lines are on GetAttitude and are this ones:

```auto

const FTeamAttitude& attitudes = teamAttitudes[Of.GetId()].Attitude;
        if (attitudes.IsValidIndex(Towards.GetId()))
        {
            return attitudes[Towards.GetId()];
        }

```

Thanks for your help so far, I really appreciate it!

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [January 12, 2019, 7:42pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/8 "2019-01-12T19:42:16Z")

</div>

> [@Gossy](#):
>
> Onto the thankfully less meaty AI Controllers and Pawns.
> 
> There’s two key things to learn here:
> 
> A **PerceptionComponent** must be on an **AIController** to work. **AIController** already inherits from **IGenericTeamAgentInterface** , but the value it returns is private, both in Blueprint and C++, AND isn’t recognized in the Reflection System. Huh…
> 
> An \*\*AIPerceptionStimuliSource \*\*needs to be on the actual **Source** Actor, which must implement the **IGenericTeamAgentInterface** in order for the _Attitude Solver_ to return an Attitude that isn’t just _ **Neutral** _.
> 
> So to get this working fully, we’ll want to Implement the \*\*IGenericTeamAgentInterface \*\*on an \*\*AAIController \*\*child class, and on any **AActor** that will have an \*\*AIPerceptionStimuliSource, \*\*returning what we want instead:
> 
> ```auto
> 
> UCLASS()
> class AMyAIController : public AAIController
> {
> GENERATED_BODY()
> public:
> 
> UPROPERTY(Category = "Artificial Intelligence", BlueprintReadWrite, EditAnywhere)
> EGameTeam AITeamID;
> 
> public:/**IGenericTeamAgentInterface*/
> 
> virtual void SetGenericTeamId(const FGenericTeamId& InTeamID) override;
> virtual FGenericTeamId GetGenericTeamId() const override;
> };
> 
> ```
> 
> ```auto
> 
> void AMyAIController::SetGenericTeamId(const FGenericTeamId & InTeamID)
> {
> AITeamID = (EGameTeam)InTeamID.GetId();
> }
> 
> FGenericTeamId AMyAIController::GetGenericTeamId() const
> {
> return uint8(AITeamID);
> }
> 
> ```
> 
> The only change to the above code for a Regular \*\*AActor \*\*class, would be to add in “, public **IGenericTeamAgentInterface** ” after “public **AActor** ”
> 
> Now, we should be done. I’ve probably forgotten something, so let me know how you go!

I have perception component in character class, and everything works fine for me. And it is easier to update character states instead of passing them from controller.  
Can you explain the difference between using perception component in AIController and Character?

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 13, 2019, 10:23pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/9 "2019-01-13T22:23:27Z")

</div>

> [@RainbowCookie32](#):
>
> That one’s fixed now. The remaining errors are:
> 
> ```auto
> 
> Settings.cpp(29) : error C2440: 'initializing': cannot convert from 'TArray<TEnumAsByte<ETeamAttitude::Type>,FDefaultAllocator>' to 'FTeamAttitude &'
> Settings.cpp(30) : error C2039: 'IsValidIndex': is not a member of 'FTeamAttitude'
> Custom.h(34): note: see declaration of 'FTeamAttitude'
> Settings.cpp(32) : error C2676: binary '': 'FTeamAttitude' does not define this operator or a conversion to a type acceptable to the predefined operator 
> 
> ```
> 
> The offending lines are on GetAttitude and are this ones:
> 
> ```auto
> 
> const FTeamAttitude& attitudes = teamAttitudes[Of.GetId()].Attitude;
> if (attitudes.IsValidIndex(Towards.GetId()))
> {
> return attitudes[Towards.GetId()];
> }
> 
> ```
> 
> Thanks for your help so far, I really appreciate it!

Soo, any ideas, anyone?

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 14, 2019, 12:19am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/10 "2019-01-14T00:19:32Z")

</div>

Well, I did some changes based on what my brain is being able to process:

```auto

ETeamAttitude::Type UPsychiatrixSettings::GetAttitude(FGenericTeamId Of, FGenericTeamId Towards)
{
    const TArray<FTeamAttitude> & teamAttitudes = Get()->TeamAttitudes;

    if (teamAttitudes.IsValidIndex(Of.GetId()) && teamAttitudes.IsValidIndex(Towards.GetId()))
    {
        const TArray<ETeamAttitude::Type> & attitudes = teamAttitudes[Of.GetId()].Attitude;
        if (attitudes.IsValidIndex(Towards.GetId()))
        {
            return attitudes[Towards.GetId()];
        }
    }
    return ETeamAttitude::Neutral;
}

```

With those changes I managed to reduce the error count to 1:

```auto

PsychiatrixSettings.cpp(27) : error C2440: 'initializing': cannot convert from 'const TArray<TEnumAsByte<ETeamAttitude::Type>,FDefaultAllocator>' to 'const TArray<ETeamAttitude::Type,FDefaultAllocator> &'

```

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 14, 2019, 6:07am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/11 "2019-01-14T06:07:51Z")

</div>

The problem seems to be related to the “array of arrays” in the USTRUCT(), but I can’t figure out how to make it work unfortunately. Any ideas anyone?

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 16, 2019, 10:24am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/12 "2019-01-16T10:24:29Z")

</div>

Hi Rainbow!

This line:

```auto

const TArray<ETeamAttitude::Type> & attitudes = teamAttitudes[Of.GetId()].Attitude;

```

Needs to match the actual type of the array, which the result would be:

```auto

const TArray<TEnumAsByte<ETeamAttitude::Type>> & attitudes = teamAttitudes[Of.GetId()].Attitude;

```

I know I didn’t put them in the example but in my code, I use the **auto** keyword a fair bit where types might be a little verbose, in which case it would look like this:

```auto

const auto & attitudes = teamAttitudes[Of.GetId()].Attitude;

```

The **&** means we are only referencing, not making a copy, of the array.  
The **const** says that we are not going to change that array.

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 16, 2019, 10:43am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/13 "2019-01-16T10:43:27Z")

</div>

> [@redbox](#):
>
> I have perception component in character class, and everything works fine for me. And it is easier to update character states instead of passing them from controller.  
> Can you explain the difference between using perception component in AIController and Character?

Sure!

In the **AIPerceptionComponent** , when it is Registered, it casts the result of _GetOwner_\*()\* to **AIController** and sets it to the _AIOwner_ property on the Component.

\*AIOwner \*is the target it uses to get **FGenericTeamId** for the \*\*AIPerceptionComponent. \*\*Without that reference, the component will always return **FGenericTeamId::NoTeam**.

```auto

FGenericTeamId UAIPerceptionComponent::GetTeamIdentifier() const
{
    return AIOwner ? FGenericTeamId::GetTeamIdentifier(AIOwner) : FGenericTeamId::NoTeam;
}

```

It is also used to set the IsHostile property on Structures passed up to blueprint:

```auto

PerceptualInfo->bIsHostile = AIOwner != NULL && FGenericTeamId::GetAttitude(AIOwner, SourcedStimulus->Source) == ETeamAttitude::Hostile;

```

So, by attaching the **AIPerceptionComponent** to a pawn, it will always be **FGenericTeamId::NoTeam** , and will aways have Neutral Attitude. It is however still useful for detecting sources.

---

<div class="post-metadata">

**Author:** ![RainbowCookie32](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RainbowCookie32](https://forums.unrealengine.com/u/RainbowCookie32)\
**Post date:** [January 16, 2019, 6:21pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/14 "2019-01-16T18:21:03Z")

</div>

> [@Gossy](#):
>
> Hi Rainbow!
> 
> This line:
> 
> ```auto
> 
> const TArray & attitudes = teamAttitudes[Of.GetId()].Attitude;
> 
> ```
> 
> Needs to match the actual type of the array, which the result would be:
> 
> ```auto
> 
> const TArray & attitudes = teamAttitudes[Of.GetId()].Attitude;
> 
> ```
> 
> I know I didn’t put them in the example but in my code, I use the **auto** keyword a fair bit where types might be a little verbose, in which case it would look like this:
> 
> ```auto
> 
> const auto & attitudes = teamAttitudes[Of.GetId()].Attitude;
> 
> ```
> 
> The **&** means we are only referencing, not making a copy, of the array.  
> The **const** says that we are not going to change that array.

Man, I really needed to hear that sweet “Compile Complete!” sound. Thanks for your help so far!

---

<div class="post-metadata">

**Author:** ![Gossy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gossy](https://forums.unrealengine.com/u/Gossy)\
**Post date:** [January 16, 2019, 10:43pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/15 "2019-01-16T22:43:42Z")

</div>

> [@RainbowCookie32](#):
>
> Man, I really needed to hear that sweet “Compile Complete!” sound. Thanks for your help so far!

Excellent! I’m glad you got it going 😃

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [January 18, 2019, 7:51am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/16 "2019-01-18T07:51:55Z")

</div>

@Gossy

> [@](#):
>
> In the **AIPerceptionComponent** , when it is Registered, it casts the result of _GetOwner_\*()\* to **AIController** and sets it to the _AIOwner_ property on the Component.

you mean when it created dynamically in runtime? But in my case it created in pawn class constructor.

---

<div class="post-metadata">

**Author:** ![redbox](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@redbox](https://forums.unrealengine.com/u/redbox)\
**Post date:** [January 18, 2019, 12:12pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/17 "2019-01-18T12:12:37Z")

</div>

@Gossy  
Oh, I think I get it. Thank you!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4346e897](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4346e897](https://forums.unrealengine.com/u/anonymous_user_4346e897)\
**Post date:** [May 9, 2019, 2:13am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/18 "2019-05-09T02:13:03Z")

</div>

Wow, this is an excellent write up Gossy. I had written a team agent interface as an attached component that was only partially working with the AI system, but with this change it is now working with functions like GetHostileActors. Thank you for taking the time to explain this!

---

<div class="post-metadata">

**Author:** ![Bitwaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bitwaker](https://forums.unrealengine.com/u/Bitwaker)\
**Post date:** [May 11, 2019, 7:50am UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/19 "2019-05-11T07:50:37Z")

</div>

I’ve just published a tutorial about this topic:

> **[UE4 AI Perception System – with just a little bit of C++](https://www.thinkandbuild.it/ue4-ai-perception-system/)**
>
> In this article I’ll go down the rabbit hole, showing how to setup and use the AI perception system. The official documentation about this topic is good but I had to scrape other needed information from various forum threads, Unreal-Answers posts and...

---

<div class="post-metadata">

**Author:** ![ValiantKT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ValiantKT](https://forums.unrealengine.com/u/ValiantKT)\
**Post date:** [June 6, 2021, 7:40pm UTC](https://forums.unrealengine.com/t/how-do-i-use-the-ai-perception-teams/120837/22 "2021-06-06T19:40:32Z")

</div>

Hi , years later, could you post a sample of your blank class that you created following this thread’s advice?

Cheers
