"Team Sense" perception AI

Hello,
I’d like to know what the “Team Sense” does and how to use it. Since there are no tutorials, the official documentation is scarce, and all I found are the two links provided below, from which I can’t gather much, even though I’m fluent in UE4’s C++.

I’d like to add logic so that if AI detects an enemy, it broadcasts the target to its nearby teammates. Can that be done using the “Team Sense”?

Hi,

I’d like to add logic so that if AI
detects an enemy, it broadcasts the
target to its nearby teammates. Can
that be done using the “Team Sense”?

yes that can be done, that is what I use it for.

I’d like to know what the “Team Sense”
does

It just sends a stimulus to all listener that have the same team and are in the specified range. Generally speaking, if you want to know what exactly a sense does you can look into its Update function.

and how to use it

I set it up some time ago where I use it, but you need to give/report a stimulus event to the PerceptionSystem. I made this function here for that which was blueprint callable

void UMyGameplayStaticsLibrary::ReportTeamEvent(AActor* InBroadcaster, AActor* InEnemy, const FVector& InLastKnowLocation, float EventRange, float PassedInfoAge, float InStrength)
{
	if (InBroadcaster)
	{
		UAIPerceptionSystem* PerceptionSystem = UAIPerceptionSystem::GetCurrent(InBroadcaster);
		if (PerceptionSystem)
		{
			FAITeamStimulusEvent Event = FAITeamStimulusEvent(InBroadcaster, InEnemy, InLastKnowLocation, EventRange, PassedInfoAge, InStrength);
			PerceptionSystem->OnEvent(Event);
		}
	}
}

One thing you need to have, is that InBroadcaster implements the GetGenericTeamId function of IGenericTeamAgentInterface (which AI controller does, for other actors you need to do so yourself).

The other thing you need, is after you change the team (SetGenericTeamId) inside your AI controller you need to tell that to the perception system, otherwise the listener will still have the old team.

So

UAIPerceptionSystem::GetCurrent(GetWorld())->UpdateListener(*this);

I had this line inside my own AI perception component, it might make more sense to do that inside your AI controller inside the SetGenericTeamId function, especially since they have this comment there =)

// @todo notify perception system that a controller changed team ID
1 Like