Spawning objects and blocked AI pathing

I have the ability to place objects in the world and i want to make sure that the AI pathing doesn’t get blocked from moving to their goal. Right now I have a function attached to the OnNavigationGenerationFinished delegate so after the object is placed and the navmesh has been updated i check to see if the path is blocked (IsPartial == true). If the path is blocked I destroy the object. To avoid flickering i have the object’s visibility turned off and only turned on if the path is valid. Is this the correct solution? I feel like i should be somehow projecting the object onto the navmesh before spawning it or something more elegant.

How would i have it indicate a invalid path before placing an object sort of like a RTS where the ground shows red if its an invalid location to place an object (blocking the path)

Hey!

Interesting question! So if I understand your question correctly you want to make sure that the path of the AI is not blocked while spawning object, to make sure the AI can always go to their given point?

To do it in Blueprints I have no immediate solution, You could expose the pathpoints from the AIController’s PathfollowingComponent->Path in c++ to Blueprints and then calculate if the path intersects with the object you spawn in worldspace.

Or do you want to make sure you don’t spawn an object on top of your AI?
To do this you could give the object you spawn a trigger and check if the trigger does not overlap with any AI characters.

Using the second option you could also make the trigger a bit bigger than the object and then check if the trigger does not overlap with any other objects. This way the AI will always have enough space to walk around the object (if the trigger is big enough of course).

I hope I am clear enough, just ask me if you need more help :slight_smile:

Good luck,

Elias

I want to make sure the path isn’t blocked. I have it working that you can’t spawn objects on top of the AI. I did everything in c++ so blueprints don’t matter to me. Think of it like a tower defense game but you can place obstacles along the way to reroute the minions. I need to make sure that the player can’t completely block off the minions from reaching the base. I’m going to add a fallback just in case where the minions destroy the object if the path does get blocked but I would like RTS style where a indicator on the ground tells the player if they can place an object there or not before they place it.

So i need some way of projecting the object onto the navmesh before creating it (unless i do my current solution where i destroy the object if it blocks the path after they place it)

I was also thinking about just creating a shell actor with just the collision that matches the object the player wants to place so the navmesh updates but i don’t waste cycles spawning an object just to destroy it.

Alright so what i ended up doing is spawning the object and having it tied to the mouse. OnNavGenFinished keeps running updating a bool if the object can be placed. If its true and the player hit the button the object is left where the cursor was. Everything works as intended for now anyway.

Unless someone has a better solution.

Ah I see, so the path of the AI is able to change after you spawn an object, you just want to check if the AI is able to path to their destination.

You could calculate yourself which part of the Navmesh will be overlapped before placing a block. And check if the Navmesh-parts are still conected afterwards.

To get the navmesh data you can take a look at this post: https://forums.unrealengine.com/showthread.php?63502-How-to-Write-Custom-UE4-AI-C-Pathing-Code-How-to-get-All-Nav-Polys-For-Custom-Code

good idea i’ll into that thanks