I have been having a problem trying to stop an object affecting the nav mesh while the game is running. I basically have a destructible mesh and want it to stop affecting the nav mesh once fractured, so that my AI can walk over the remains. It seems you can not change the bool for “Can ever affect navigation” through blueprint (None that I have found anyhow).
I would just like to know if it is possible to stop it affecting the nav mesh while in run time and how to do this?
Thank you in advance for any help and replies to this post.
I found a way to change this bool at runtime. If you go ActorComponent.h, there is a method called SetCanEverAffectNavigation, just put a UFUNCTION(BlueprintCallable, Category=“Collision”) (This category allows you to find this method in blueprint collision category) on top of it to make it a UFUNCTION which can be called from blueprint. Recompile your engine after this change and it should work.
YuchenMei,
sorry I know this is a while ago, but could you guide me how to do this. Im quite new at C++ in UE4. I tried adding the code above in the line above SetCanEverAffectNavigation and rebuilding both the game and the engine but this didnt help anything.
Ok, so in your blueprint, you should be able to call the function SetCanEverAffectNavigation and the target is the static mesh you want to change whether it affects the navigation. If you set the tCanEverAffectNavigation to false of the static mesh, it should stop this static mesh from affecting the navmesh.
Let me know if I am not explaining it well and it would be better to describe what you want to do more.
Hi Yuchen,
Sorry i dont think i was clear. I want to be able to expose and call’SetCanEverAffectNavigation’ on static meshes spawned at runtime (which is currently not exposed in BP). These do not have this option at present, so how do you modify the C++ code in actorcomponent.h, because ive tried and it didnt seem to work (reading your post I assume you know how).
EDIT: Okay, I found where to add the UFUNCTION line at and I’ve compiled just fine, but this still doesn’t show up in Blueprints. Can’t search, nor find it in the collisions section.
For Pawn, you can use function Set Can Affect Navigation. You should disable Context Sensitive in All Actions For Blueprint to find it.
For non Pawn actors, you can create NavLink and dynamically switch it.
Simplest method is to create Nav Modifier Volume with null and destroy it when destructible will be destroyed. I’m using mixed solutions depending on situation.
Well, this all is not need if you have dynamic Nav Mesh update on of course
Thank you for all the alternate solutions. I found one that would work for my game using a modifier volume. Much simpler than the original solution proposed.
I struggled with the same problem but found a nice workaround. You cannot change whether it affects navigation at runtime, BUT you can set “Can Ever Affect Navigation” to true, and then use “Set Collision Response to Chnnel” for Pawn and Vehicle collision channels to ignore/block depending on if you want to rebuild the navigation or not. If you set them to block then NavMesh’ll dynamically rebuild the navigation, if you set them to ignore the NavMesh somehow won’t detect them and won’t rebuild the navigation. Hope it helps.
I think I found the intended approach to achieve the desired behaviour.
First, go to Project Settings → Navigation Mesh → Runtime and set Runtime Generation = Dynamic Modifiers Only. You can’t keep it at the default value of Static, but Dynamic is worse for performance and is not required in the use case of enabling/disabling collision on an otherwise static object.
As far as I am aware, there are two ways to create such dynamic modifiers - by using a Nav Modifier component or by using a Shape Component with a flag Dynamic Obstacle = true. We are going to use the second way because dynamic obstacles both provide colliders and modify NavMesh at runtime when their collision settings change. Meanwhile Nav Modifier component has no collision and it expects its parent actor to have collision from some other components. It’s just more bothersome to work with.
So, go to your actor and untick Can Ever Affect Navigation from all components that have it, because they are not dynamic modifiers. You might as well just disable all collisions to keep things cleaner. Instead, add a Box Collision, Sphere Collision or Capsule Collision component (any subclass of UShapeComponent is fine), configure its size and collision in a way that suits your purpose, and then tick Can Ever Affect Navigation = true and Dynamic Obstacle = true.
If you did everything right you will now see the area around your actor highlighted in orange in the editor with Navigation visualization enabled. From now on, just calling a Set Collision Enabled blueprint node in runtime is enough to enable or disable this orange area of NavMesh.