Hi @Jaegermeiste , well you’re on the right track with Edit 2 and we can use Event Dispatchers to let the spawn points know when they should update the nav path splines.
But before getting to that, first make sure that the Runtime Generation parameter of your **RecastNavMesh **is set to Dynamic Modifiers Only.
This will ensure that the Nav Modifier Volume in our Towers can affect the Nav Mesh at runtime.
The next step is to head over to the **BP_Tower_Parent **blueprint and set the Area Class for its **NavModifierVolume **component to either NavArea_Null or NavArea_Obstacle. The former ensures that no unit will ever traverse through a grid cell containing a Tower while the latter allows for some flexibility when there is no other path to objective. IIRC, this became an issue only when you place a tower on a grid cell which already contains an enemy moving through it.
At that point, if you’re using the Null option, I’d suggest destroying every enemy unit around the Tower when it is spawned so as to prevent the AI getting stuck. On the other hand, with the Obstacle option, I believe it might be able to pass through if going back is not an option.
Finally, just play around with the Box Extent for the component to control how big of a hole is cut into the nav mesh when you spawn in a Tower. And that’s all we have to do with respect to the Tower BP modifications.
Next, we need to set up an Event Dispatcher system that gets called whenever a Tower is created/destroyed. Since this is handled by BP_TowerManager, that would be a good place to have this logic. So open up the blueprint and add a new Event Dispatcher “TowerSpawned/Destroyed”. Then head over to the **SpawnTower **& **DestroyTower **functions, and call the new dispatcher as shown below:
Next, we want to have the Spawn Points listen to this dispatcher, but since our paths are going to change dynamically, we also have to store references to the spline mesh components and have them destroyed before creating a new one. So open up the **DisplayAIPathUsingSplineMeshes **function of BP_SpawnPoint, and add the following logic:
Finally, head over to the **BP_SpawnPoint_NavMeshPathing **blueprint and make the following modifications in its Event Graph:
This will ensure that, everytime a Tower gets created or destroyed, the Spawn Point immediately gets around to updating the nav path splines. The AI movement should be automatically updated by Unreal’s nav mesh system.
And I believe that’s all there is to it. You should now be able to have the Towers influence the nav path display, but let me know if you have any doubts regarding the workflow.