Download

Problem with using AIPerception's Team Sense

Hi, I am trying to use AIPerception’s Team Sense (additional to Sight and Hearing).

Now I have the problem that I can’t seem to get it working. I already did the following:

  • Added the sense to the AIPerceptionComponent in the AIController; Max Age is 0.0f
  • Added a Stimuli Source Component to the AIController (doesn’t work on pawn also), call RegisterSource… and RegisterSense(UAISense_Team::StaticClass()) (or sth like that) AND in Blueprint override set Auto Register and added Team sense
  • Call UAIPerceptionSystem::OnEvent with custom settings
  • Listener and Broadcaster are both AIControllers with the same GenericTeamId, so sense should be triggered

But unfortunately I never receive Team Stimulus in OnTargetPerceptionUpdated
Here is some code:



void AZombieAIController::BroadcastTarget(AActor* Target)
{
    FAITeamStimulusEvent TeamEvent = FAITeamStimulusEvent(this, Target, Target->GetActorLocation(), 100000.0f);
    UAIPerceptionSystem::OnEvent(GetWorld(), TeamEvent);
}

...

if (Stimulus.Type == UAISense::GetSenseID(UAISense_Team::StaticClass()))
{
     // Never triggered
     SetTargetLocation(Stimulus.StimulusLocation);
}


OnEvent() are declared with template. so, you have to specify your Event Class and SenseClass like below


UAIPerceptionSystem::OnEvent<FAITeamStimulusEvent, FAITeamStimulusEvent::FSenseClass>(GetWorld(), FAITeamStimulusEvent(GetPawn(), InEnemy, InEnemy->GetActorLocation(), TeamEventRange));

Hi,
Sorry for necroing this but I have the exact same problem.

I have 2 enemies.
In OnTargetPerceptionUpdated, I’m calling that OnEvent() function.
I put a breakpoint in OnTargetPerceptionUpdated and play the game.

When I detect an enemy, I expect the breakpoint to fire twice, since there are 2 enemies and the first one is calling OnEvent which should broadcast the event and call OnTargetPerceptionUpdated on the 2nd enemy. It doesn’t fire twice :frowning:

I’ve set a StimuliSourceComponent on my EnemyActor with UAISense_Team and Auto Register as Source to true.

Any ideas? Thanks a lot!

Hi again,
I finally found out! :slight_smile:
After setting the TeamId, you must update the listener.
So, in BeginPlay() for example:


SetGenericTeamId( FGenericTeamId( 1 ) );
UAIPerceptionSystem::GetCurrent( GetWorld() )->UpdateListener( *PerceptionComponent );

The issue was that the perception component of each AI was registered to the global perception system when the team id of each enemy was not set.
Hope this helps!