How to add Pawnsensing to my AI Behaviortree?

Hi there, so i was following along this [tutorial][1] to check if the AI is seeing the player and i am really confused.
Currently to check if the AI is in sight i use this code :

but i was wondering if i could also use pawnsensing for that. I tried it in different ways but everything i could think of gave me errors.

I also would like to add the hearing sense.

I read a post where someone suggested using AI perception about pawnsensing for that but what the heck ist AI perception ?

Thanks !

Hi,

You might want to take a look at this official tutorial on using AIPeception and behavior trees. You can also use PawnSensing which works in a similar way as AIPerception. However, PawnSensing is no longer supported and I suggest you use AIPerception instead which is not only more efficient but also gives you more control over your AI sensing. In either case, I suggest you use these out of the box powerful tools that Unreal Engine equips you with instead of reinventing the wheel and implementing your own AI vision algorithm.

Another thing to note here is that AIPerception is not well documented yet. Though, that tutorial alone should be enough to get you started with AIPerception and behavior trees. From there on, you would have to rely on Google, forums and this AnswerHub to learn more.

Hope this helps.

Hi Vizgin, thanks again for your answer !

I suggest you use these out of the box powerful tools that Unreal Engine equips you with instead of reinventing the wheel and implementing your own AI vision algorithm.

Thats what i was thinking as i followed the tutorial. Since i am a complete noob (started with AI a week ago), i think the tutorial that you posted is a bit to advanced but i will definitly look it up.

However, it think i will go with pawnsensing first and maybe change as my knowledge increases. Can you tell me how i can implement the senses into my behavior tree ?

At first, i was building the AI in the BlueprintClass and the senses worked, but the steps were executed very sloppy and bugs occured.

Much thanks !

Behavior tree is considered advanced! So, if you want to learn it, the best place to start is that official tutorial I already sent you. In general, though, using AIPerception or PawnSensing isn’t difficult at all. Here’s a fast and simple guide on how to get PawnSensing working. Start by simply adding it as a component to your Character or its AIController. Once added, it will show up in the components list which you can select and tune its parameters in the details panel. Next, while this component is selected, scroll all the way down in the details panel and select On See Pawn. The Engine will add a new event that will fire once a pawn enters its zone. The output pin Pawn represents the other pawn who has entered the AI’s vision zone. You can then implement any AI behavior you like in here. Here’s an example where I helped someone fix his simple AI following logic that might be useful to you.

Cheers :slight_smile:

Hey, thanks again for your answer ! The thing is, i know how to use the OnSeePawn in the Character or AIControllers EventGraph. But i am not sure how to call it in a BehaviortreeService (the one in the image) or if this is even the right way to access the pawnsening component. As you can see here

i am running the Visioncheck where the “sensingcode” is called. I didnt find a way to access the pawnsensing component in this Service. Here are some more detailed images of the Visioncheck Code

Maybe im completely wrong with my attempt :frowning:

I don’t see you using PawnSensing anywhere in this setup! You’ve reimplemented the pawn vision system based on that tutorial you initially posted and frankly, this is not the best or most efficient way of doing it. You don’t need a service node for PawnSensing to work. You would instead use a blackboard decorator as a condition check and change the value of decorator in your AIController. Here’s a very simple AI system using AIPerception and behavior tree to move the AI pawn towards the player (I’m using AIPerception for reasons I told you before and also because it makes setting up the logic easier by giving me that extra boolean input that is true when the AI has seen the pawn and false when it has lost sight of it. You would also need a NavMesh for behavior tree task Move To to work).

AIController:

Blackboard

226784-blackboard.png

Behavior Tree

Though this simple dumb AI will probably chase you forever if your speeds are the same :smiley: Try to get out of its sight (maybe with spectator pawn) and you’ll see that the decorator OtherPawn will become null, causing the selector to fail and your AI to stop in its place.

Awesome, it worked ! Thanks a lot, i didnt think of such a simple way, i feel kinda silly now :smiley:

So the VisionCheckService also spawns targetpoint actors that store the location where the player was last seen, so unless i find a better way to do that, i will keep it^^

I have decided to use perception because of your example.

I have seen that i can specify the Perception Stimuli to what sense should be stimulated.

Can you tell me how i differenciate between those two senses when i want to call it, because my AI should act diffrently when he hears something as when he sees something. (in your example i can only see “successfully sensed” as boolean option.

Thanks a bunch for staying with me, the UE community really makes learning the engine fun :slight_smile: