AI Perception

Does anyone else find that AI Sight perception is the most unreliable thing imaginable? Maybe its my setup, but it seems like it works fine on some maps and not on others. works one day, not the next. I’m constantly changing stuff around and tinkering with things that worked fine before with no changes. Anyone else get this vibe? Any help appreciated. posting an image of my AI controller.

Hi @TLOA

I am inclined to agree with you. Sometimes the ai will forget about me beyond its visual range then sometimes it will see me regardless of distance.

I must say that the perception events are very unintuitive and im wondering when theres heavier processing going on that sometimes events arent firing or overlapping.

Mine is at its worst the more ai i have on the screen at once. Its like all the ai are sharing the same eyes so they all see me when 1 does.

There needs to be a seperate event for lost sense, rather than just update sense for everything. Like beginoverlap and endoverlap.

I am considering writing my own , but for now ive switched to Pawn Sensing . But there is a little less control as there is only 1 sensing cone, where as ai perception has a seen and a lost radius which can be seperate.

So are we missing something here? Is this still a work in progress?

1 Like

With your pawn sensing, do all of your enemies at least still see you and attack? Also, can you still get them to patroll? If so, i feel like i could settle for that. Do you have a good recommended tut?

The AI Sight config by default looks at a single point in the actor, if I recall correctly in the default characters it’s around the middle of the character mesh. So character visual can be lost even when “most” of the character is still visible. Recommend looking into overriding CanBeSeenFrom in C++ to configure more sight points.

Also I’d only update blackboard values with the sight updates and run the logic on the behavior tree side of things. I wouldn’t set up a timer to update the sight config, also if there are multiple players it can bring about issues if implemented naively.

1 Like

I posted the same thing on reddit and several people mentioned that timer! I just tried deleting it and setting everything upi n the bx tree but im failing there too. Below is the current bx tree. Nothi ng special. When i am in line of sight of an enemy, the black board sequence node says failed.

As for the component that “isSeen,” thay would be my root. I tried updating that to higher points and the bx is the same. I really appreciate your reply and any further feedback.

Instead of the AND boolean try to check if it is a player first and then check for sense update. It can fail if it is not a player but another AI that it is sensing, and then trigger the sight loss.

See i have issies with mine, and mine should be set up properly with no timers, i send updates to the behaviour tree blackboard but the sense thing is sometimes reliable sometimes not. More unreliable when sensing lost perception.

The ai picks up the player but doesnt lose sight reliably. In debug mode the ai range seems to go infinite sometimes when way outside the lose sight boundary. The floor goes green everywhere i step regardless of range.

Then othertimes it just plays nice.

And yes i distinguish between players and check the sense value is true or false

thanks for the suggestion. i gave it a shot:

Get player char = other actor to branch, if true break AIStim. Its still not working. Im really struggling :frowning:

Same here. I just dont get why it works perfectly in some levels and is just shotty in other levels. Im almost at the point where im ready to hire someone to tell me what the deal is.

Well right now i switched to pawn sensing until i figure it out, maybe rewrite the Ai Perception code later and see what gives

1 Like

Can you point me to a good pawn sensing tut? Are your enemies still patrolling with pawn sense? I found a couple tuts but they wont patrol

the patrol i use my own code, theres a brief hanging about (its a zombie hes brain dead) then he finds a random reachable point in range then walks to it, then if interupted by the pawn sense he goes and chases the pawn til he can no longer find him then returns to his duties after.

pawn sensing default checks are .5 second. so the retrig delay i set at 1 second, if it dont retrigger the pawn no longer sees you so clear the target. if it retriggers it sets the target actor. you can delay this a little longer for maybe allow them to ermember you for a longer while

1 Like

That a great setup. I tried to do something similar but it looks like its not yielding the result i want. I might have to work on it a bit but maybe this is the answer. Ill update with resolution if i can get one! Thank you very much!

1 Like

its simple, not perfect but works :slight_smile: but that said im going to look into the AI Perception again myself and see if i cant refigure this out.

hmm im totally baffled now. i decided to scale my test down a little and my new basic Ai Perception code works great with 25 Ai Zombies on screen, i get to about 75 still works ok, but as i add and add i think i got to 175 and it all goes crazy, SO im thinking there is a limit on AI remembering (there is an array holding sensed pawns) so as i can distinguish in blueprints neutral/enemy/friend (only works on neutral in blueprintsa apparently) i think the AI is getting messed up sensing too many other pawns.

It needs someway of either only allowing, or dissallowing , or even fix it to set enemy neutral or friendly on the pawns and work as intended.

25 to 75 Zombs

150 or so then upto 175

There is only one zombie i the debug but at the top middle section the last variable is target actor. on the first video 25 zombs the sense works as intended.
2nd video with 75 works as intended but when i hit 175 it never forgets the player.

I could manually add in a distance check possibly or ray trace to see if im seen. but then i might as well write my own routine to do the same thing.

1 Like

I think i finally cracked it!

Ok by default ALL pawns are registered as sense stimuli , this coupled with the apparent (undocumented) limit on the number of pawns that can be sensed at any given time.

So the fix?

Close your project
Navigate to you project folder
Inside the “Config” folder open up and edit “DefaultGame.ini”
Add the following line of code (presuming it doesnt exist, if it does modify it to match)

[/Script/AIModule.AISense_Sight]
bAutoRegisterAllPawnsAsSources=false

Save and close and reload your project.

Now on the player(s) pawns you wish to detect (probably on the base class if you create child classes!)

Add in an AIPerceptionStimuliSource and click on it to select it once added

Untitled

Then in the details panel on the right find the AI Perception section and:

  1. Auto Register as Source is ticked (wont work without it!)
  2. Add in your Senses using the + next to “Register as Source for Senses” (I Chose only sight for now)

Untitled1

Now when i run no matter how many actors are in the cone angle, only players with this component attached are sensed. Tho other actors can block the view which i guess is realistic, I have a last known position setting so they still wander towards there. You can also set a radius from the last known position also that it can see around.

Mine is working nicely and last checked with 300 Zombies running… erm creeping around!

On a side note maybe this option should be in the project settings, even if it does require a reboot, a simple tick box with a message saying restart the editor would be much more helpful!

And it appears from early 4.xx days the enemy/neutral/friendly assignment in blueprints has never been available, only in c++. Surely this by now could have/ should have been implemented?

tested with nearly 500 Zombies and still works!

1 Like

If you mean in AI debug mode, that’s an indicator that the AI is presently on a path that goes through that poly. That is not an indicator of what it can see/hear.

Yes i know it was to show the path tracing for the AI in question when it shouldnt KNOW it should go to my last known location. But because it wasnt registering forgetting my pawn it kept attempting to reach me whence the green tiles everywhere for the pathing, its default roaming path is only 3000 units so i knew the AI was still path finding me.

1 Like

Since the last time i checked in i started looking really deep into pawn sensing and actually got that working the way i wanted with one caveat. I have it set up to make enemies wander until they spot me, and then chase and attack. The problem is that enemies will wander into wall, or each other, and get stcuk there. They might still see me, but in groups of like 3 or 4 enemies, they seem to block each other. I think the random nav point they find maybe ignores walls and other pawns? Either way, if there is no answer to that ill probably just rebuild ai sense and try what youve done here because it is brilliant!

Youvneed to make sure you use random reachable point when wandering, thats how i do it. They wander , if they see me follow me, lose sight the go to the last known location then there is a wait rask random time 3 to 10 seconds rhen go back to roaming.