Change AIPerception Senses Per Pawn?

Hello!

I have an Enemy AI that I’m working on that uses the default Perception Component on the AI Controller. The Enemy_Base pawn class that implements the controller has variables for configuring how the enemy will react to other enemies and the player. This was so I could create a subclass of Enemy_Base and simply edit these variables to create another enemy. No extra work or classes necessary.

However, I’ve discovered there’s no simple way to edit the Senses Config on the Perception Component. Given enemies in the game will have different perceptions (some might see better, while some might hear better, etc), this is necessary.

I can’t set the Senses Config at runtime, otherwise I would’ve tried creating the same variable on the pawn and setting it on Begin Play (and I imagine this has to do with the initialization of perception, otherwise I would’ve simply overridden the variable in C++ to have BlueprintReadWrite). If I add a Perception Component to the pawn, I get numerous warnings stating that it is “designed to work with AAIControllers!” I’ve searched multiple classes related to the AI for functions that might help, but no luck.

Thus far, the only solution I can see is to create a child of the AI Controller for every new enemy, which seems inefficient. I’m hoping that someone has thought of this before and has a solution. I would’ve thought this would be common, but I can’t find any posts about it anywhere.

Any and all help is appreciated!

Engine version: 5.1

The perception component should be in the pawn. Though there is a built-in workaround to make the perception component work via controllers, it’s meant to be on the pawn.
You want it on the pawn anyways to override it easily.

Also, if it’s just seeing and hearing, you may just want to use a pawn sensing component instead.
It can be changed at runtime.

I can’t reproduce your “designed to work with AAIControllers!” error neither in bp nor cpp…

@rokenrock Thanks for the response!

Glad to know I can just attach it to the pawn. That makes things easier.

As for the pawn sensing component, I’ll be making use of the other senses, so Pawn Sensing won’t work for my case. I only listed Seeing and Hearing because those are the only ones I think will change per enemy.

As for the warning (it’s not an error), I found it in the Output Log. Here’s what it says:

LogAIPerception: Warning: UAIPerceptionComponent::OnRegister: Perception Component is being registered with Enemy_Base_C_0, they are designed to work with AAIControllers!

This warning occurs about 18 times anytime I make a change to the Enemy_Base class. The only difference is some say Enemy_Base_C_1 or Enemy_Base_C_2 instead, regardless if an Enemy_Base is in the world.

In all honesty, I’ll probably ignore it. I thought that due to the amount of them that I must be doing something wrong as I’ve never seen anything logged this much without being on Tick (plus the documentation only ever mentions it being attached to the Controller). But, it is a warning after all, simply stating that it wasn’t designed to work with anything other than an AI Controller. If people have done it before without problems, that’s good enough for me.

Thanks again!

1 Like