Perception Component Added in C++ wont allow Senses Config in Derived Blueprint

Hi there,

I’m creating a Perception Component in C++ on my AIController

SetPerceptionComponent(*CreateDefaultSubobject<UAIPerceptionComponent>("Perception Component"));

I’ve also tried on a Character but the result is the same

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Wizen AI", meta = (AllowPrivateAccess = "true")) //Tried many combinations 
class UAIPerceptionComponent* PerceptionComponent;

PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>("Perception Component");	
PerceptionComponent->bEditableWhenInherited = true;

When I create a blueprint derived from the class with the perception component I can’t set “Senses Config” items. I can add to the array but when selecting an item from the list it remains as “None”. However I am able to change the “Dominant Sense” value.

Weirdly, if I Add another Perception Component to the blueprint, I can copy a value from the “Senses Config” list and paste it on the C++ created component and it does appear to be set. But then some of it’s sub properties aren’t editable: “Detection By Affiliation” doesn’t show the dropdown and tick boxes.

I am having the same issue. I will post if I figure it out.

Got it… Kinda. I couldn’t get it to set in the editor but I was able to set up some C++ in the constructor to expose the Sight Config to the editor.

Header:

protected:

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Perception")
class UAIPerceptionComponent* PerceptionComp = nullptr;

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Perception")
	class UAISenseConfig_Sight* Sight = nullptr;

CPP:

Sight = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Sense"));
if (Sight)
{
	// Sight configuration
	Sight->SightRadius = 500;
	Sight->LoseSightRadius = 600;
	Sight->PeripheralVisionAngleDegrees = 180.0f;
	Sight->DetectionByAffiliation.bDetectEnemies = true;
	Sight->DetectionByAffiliation.bDetectNeutrals = true;
	Sight->DetectionByAffiliation.bDetectFriendlies = true;

	PerceptionComp->ConfigureSense(*Sight);
}

I hope that helps!

I managed to get the component editible from within blueprint using this declaration in the header

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = AI)
UAIPerceptionComponent* AIPerception;

And this in my cpp constructor

AIPerception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AIPerception"));
SetPerceptionComponent(*AIPerception);
AIPerception->bEditableWhenInherited = true;

For some reason though, the “Detection by Affiliation” checkboxes are still hidden from the blueprint component config, but you can edit their values by copying this to your clipboard

(bDetectEnemies=True,bDetectNeutrals=True,bDetectFriendlies=True)

right clicking on “Detection by Affiliation” and pressing paste.

Hope this helps!

Thank you so much! I spent hours trying to figure out what was up with this weird behavior. Still can’t create or edit existing Senses Config from editor, but at least with your solution I can edit the values in editor.

2022, problem still exist…
Is it bug or some expected behaviour for inheritance?
What can i do if i want set some preset configs in C++ and give blueprint user opportunity to extend perception senses and configs?
Is this problem exist in ue5 too?

1 Like