AIPerceptionComponent in C++ does not display "Detection by affiliation"

Hi,

When I add the AIPerceptionSystemComponent in the BluePrint editor, and add a sense to the SensesConfig, the DetectionByAffiliation is correctly displayed : it is expanded, and I can check the 3 checkboxes.

But when I create the perception system in C++, the DetectionByAffiliation is not expandable, and I can’t change the value. More importantly, even changing the values in code doesn’t seem to be reflected at runtime. When I use the blueprint version, and log some text in the event called when the perception is updated, I have some logs.
Using the same settings in the C++ version, nothing is displayed, because the affiliation check fails in FAISenseAffiliationFilter::ShouldSenseTeam in the Update function of UAISense_Hearing for example.

Here is the code I use in C++ to configure all that stuff:

ARWCAIController::ARWCAIController( const FObjectInitializer& ObjectInitializer )
    : Super( ObjectInitializer )
{
    BlackBoardComponent = CreateDefaultSubobject< UBlackboardComponent >( TEXT( "BlackBoardComp" ) );
    BehaviourTreeComponent = CreateDefaultSubobject< UBehaviorTreeComponent >( TEXT( "BehaviourTreeComp" ) );
    
    SetPerceptionComponent( *CreateDefaultSubobject< UAIPerceptionComponent >( TEXT( "PerceptionComp" ) ) );
    SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>( TEXT( "Sight Config" ) );

    SightConfig->SightRadius = 300.0f;
    SightConfig->PeripheralVisionAngleDegrees = 360.0f;
    SightConfig->DetectionByAffiliation.bDetectEnemies = true;
    SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
    SightConfig->DetectionByAffiliation.bDetectNeutrals = true;

    GetPerceptionComponent()->ConfigureSense( *SightConfig );
    GetPerceptionComponent()->SetDominantSense( SightConfig->GetSenseImplementation() );

    HearingConfig = CreateDefaultSubobject<UAISenseConfig_Hearing>( TEXT( "Hearing Config" ) );
    HearingConfig->DetectionByAffiliation.bDetectEnemies = true;
    HearingConfig->DetectionByAffiliation.bDetectFriendlies = true;
    HearingConfig->DetectionByAffiliation.bDetectNeutrals = true;

    GetPerceptionComponent()->ConfigureSense( *HearingConfig );

    GetPerceptionComponent()->OnPerceptionUpdated.AddDynamic( this, &ARWCAIController::OnSightPerceptionUpdated );
}

Note that I tried to not create the sense config objects in code and add them in the Editor, but the same problem remains…

Is this a bug, or is it me not correctly initializing the component?

Thanks!

Thank you for your answer :slight_smile:

Do we have access to your ticket report system? This would have allowed me to not post here if I has found the bug was already reported

Hello Zoubi,

I have investigated this issue and discovered that it is a known issue (UE-18378). Thank you for your report. I will update the bug report with this post.

Have a great day

We currently do not have a way for the public to track our bug reports.

If you are ever wondering if an issue has been reported, however, you can perform a search on Unreal Engine 4 Documentation | Unreal Engine Documentation

This will allow you to search the documentation, forums, Answerhub, and wiki for information regarding your issue.

Have a great day

This is a gnarly bug! Any chance it’s been fixed?

This issue is still being investigated by our developers, however, there is no timeline for when a fix will be released at this time.

Hello I just encountered the same issue with the newest release 4.15, is there any workaround to this?

Hey nullbot,

You can track the issue’s status using the link below: Unreal Engine Issues and Bug Tracker (UE-18378)

Currently, I’m not aware of any known workarounds.

Have a great day

I added the component in the blueprint directly, and in code I call GetPerceptionComponent() instead of using directly the pointer. That is the only workaround I found

Sorry about bump this thread up. I found this issue had been add a fix commit and last updated was at Jan 25, 2018. Is that means the issue had been solved? If yes, will the commit be merged into 4.19?

At this time the ticket is still unresolved. Those fix commits are from a previous version of the fix that ended up needing to be re-evaluated. Once a new fix version is available, it will appear on the public ticket.

I was surprised to discover how long this has been a bug. I did find a decent workaround you can do get it populated in the editor. First, temporarily add another AIPerceptionComponent to your Controller Blueprint. The editor added one will have Detection as Affiliation populated, you can set it however you like. Once you’ve done that, if you right click and pick copy, you can then go to the inherited one and right click on ‘Detection as Affliation’ and pick paste. It will copy those values into it. The underlying struct is still there, just the Editor UI is busted. After you paste it over, you can just delete the one you added. You could even keep it pasted in a text file and keep it that way if you don’t like adding fake components constantly. If you want to inspect what is already set, you can copy it and paste it into a text file to check the values.

On July 10, 2019, this problem remains unsolved, in UE 4.22.3.