I have this npc that follows sound lures when they are activated, the way it work is: when the player activates the lure the ai move to that lure location through the shortest path via nav mesh, but sometimes there is obstacles in the way that dont influence the nav mesh and the ai keeps bumping those obstacles instead of finding a clean way:
As you can see here the door doesnt mess with the nav mesh, and some doors are locked and can be unlocked and sometimes the ai keeps trying to pass trough those doors instead of going other way, how do I fix that?
This is a fairly complex topic and it’s largely dependent on your desired result. For instance, if your NPCs can open doors then you’ll likely need some collision box on the door that can detect overlaps with an NPC and then direct the NPC to run an open door animation. If they can’t open the door then you’re going to need to block that path from the nav mesh. Off the top of my head I’m unsure how to do that.
With a dynamic navmesh that should be fairly trivial. When the door is closed, set bCanAffectNavigationGeneration to true. That way the navmesh is rebuild taking the doors collision as blocking into account, and your agent won’t try to walk that way. When the door is opening, set bCanAffectNavigationGeneration to false, depending on how your animation works, wait till it is open and not moving again and set it to true again.
Hey @Lamaral14, I think what you want is a NavMesh Modifier. You want your doors to modify the navmesh, blocking it when closed and enabling it when open.
There is a node called “Does the path exists?”, which can be used
as a condition to the “move to” node.
More refined workflows would also include:
Add an actor tag to the enemy and whenever the AI appoaches a closed door, the door overlap event checks “actor has a tag?” and the door opens.
The thig is that the CanAffectNavigationGeneration doesnt seem to work with meshes only pawns, i already changed my bp to a pawn and did that thing in the event tick above but no changes, the mesh only changes when i check the box of the door mesh and cant program it because i cant acess it
Is your nav mesh set to dynamic? I’m not sure what you mean with “no changes” because your screenshot clearly shows that the door is now blocking the navmesh.
The thig is that the CanAffectNavigationGeneration doesnt seem to work with meshes only pawns
No, it works with all actors that have a collision.
It is set to dynamic, please let me be more clear:
1st- the changes only happen when i checked the box " Can ever affect navigation" on the “door” mesh, the problem is that i cant program that because i cant acess it in the blueprint
2nd- I used the “CanAffectNavigationGeneration” node requires a pawn as target, my door bp is now set to be a pawn, but its not changing the nav mesh:
In this case i uncheck the box of the “door” mesh mentioned before (the one i cant program), and you can see that the variable " is door locked" is set to true and its not changing the mesh
I understand now, the property is not exposed to blueprint but in c++ … kribbeck idea with the navmesh modifier is then the next best thing. That should be able to toggle in blueprint.
Im gonna try that, but shouldnt the “CanAffectNavigationGeneration” node be working since the door is a pawn? why does not work can you explain me please?
So at this time, i’m not sure. Maybe a restart could help. But setting it to dynamic, should allow you to do what i show in the video. If that doesn’t work, then your nav mesh generation has problems. That can be solved by deleting RecastNavMesh-Default, restarting and rebuilding the navigation