AI Perception fails to detect sight when using blueprint nativize conversion when building game

I was using AI perception to detect my player object and it was working fine in the editor however when i cooked the game to be distributed i used the nativize blueprints feature and it was causing the AI not to see the player anymore…I rebuilt the game and compiled it with the feature turned off and it seemed to work fine. Not sure if this is noted yet or not…but it caused me headaches for a long time :frowning:

Hello warka,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Can you reproduce this issue in a clean project?
  2. If so, could you provide a detailed list of steps to reproduce this issue on our end?
  3. Could you provide screen shots of any blueprints/settings that may be involved?

I’m having the exact same problem, however I’m using Unreal 4.15. If I nativeize all the blueprints in my project, by using the Project Settings: Packaging → Blueprints → Blueprint Nativization Method set to “Inclusive”, then AI Perception fails to sense/see player controlled pawns. When setting Packaging → Blueprints → Blueprint Nativization Method back to disabled, AI then senses as expected.

I’ve created a new project with just the assets that showcase the issue.

If you download that project and play in editor, the ai character will chase the player pawn if it gets close. If you package the project and execute the build it will not.

However if you change the Project Settings: Packaging → Blueprints → Blueprint Nativization Method set to “Disabled”. Then the AI will chases you in a packaged build.

Hey HyperToxic,

Thanks for the info and the project. I’ve reproduced the issue in both your project and a clean project and have written up a bug report, which you can track using the link below:

Have a great day

Hi Sean,

I also experience this issue. In my case the problem is that nativization makes new objects for Senses for AIPerception component that was made in C++. Also when nativization makes code for sense it does not set DetectionByAffiliation.

Here is STR (UE4.16.3):

  1. Make empty project
  2. add AIController parent class to C++ and add AIPerceptionComponent to it with several senses
  3. make BP AIController derived from one created in C++
  4. Build the project with nativization. When build Development you will get an exception on start.

Fatal error: [File:D:\Build++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 3615]
Default subobject AISenseConfig_Sight SenseSight Config already exists for AIC_EnemyBase_C /Game/Blueprints/AIC_EnemyBase.Default__AIC_EnemyBase_C.

example project: https://drive.google.com/file/d/1UZLf37dy2EY0ehcmDcxzvKkEQQemZcpd/view?usp=sharing

Have a nice day

Here is workaround in case AIPerception Component added to Blueprint.

declare function in C++ and call it in BeginPlay

header:

UFUNCTION(BlueprintCallable, Category = "Helper")
void UpdateDetectionByAffiliation();

cpp:

void AAIC_BaseCPP::UpdateDetectionByAffiliation()
{
	UAIPerceptionComponent *percComp = GetAIPerceptionComponent();
	if (!percComp)
		return;
	
	UAISenseConfig_Sight *sightConfig = Cast<UAISenseConfig_Sight>(percComp->GetSenseConfig(UAISense::GetSenseID(UAISense_Sight::StaticClass())));
	if (sightConfig)
	{
		sightConfig->DetectionByAffiliation.bDetectEnemies = true;
		sightConfig->DetectionByAffiliation.bDetectFriendlies = true;
		sightConfig->DetectionByAffiliation.bDetectNeutrals = true;
	}

	UAISenseConfig_Hearing *hearingConfig = Cast<UAISenseConfig_Hearing>(percComp->GetSenseConfig(UAISense::GetSenseID(UAISense_Hearing::StaticClass())));
	if (hearingConfig)
	{
		sightConfig->DetectionByAffiliation.bDetectEnemies = true;
		sightConfig->DetectionByAffiliation.bDetectFriendlies = true;
		sightConfig->DetectionByAffiliation.bDetectNeutrals = true;
	}

	percComp->RequestStimuliListenerUpdate();
}