How to change navigation cost in realtime

In our game, the player builds roads (these are square tile pieces). I am looking for a way to make the ai prefer to walk on roads if possible.

The only method I’ve seen so far is to use a NavMeshModifier volume, but I haven’t been successful in spawning one at runtime.

Is there a suggested method of handling realtime navigation cost changes? (Either in c++ or blueprint)

Thanks in advance

Rama is making great dynamic AI system

, pm him

Thanks Tim, that looks like a really great system but unfortunately Rama re-invented his own system entirely, I simply need to modify the navigation cost (I imagine this should be possible with the existing navmesh system).

Well, you can ask him what’s the best wy to implement it in your case.

#Solution

  • Make a BP of NavArea_Default

  • Set the custom cost value as seen in picture!

  • Make a c++ class that extends the nav modifier volume

  • Set its mobility to moveable in the constructor!

  • You should now be able to spawn it at runtime, position and resize it!

    UCLASS(hidecategories=(Navigation, “AI|Navigation”))
    class ANavModifierVolume : public AVolume, public INavRelevantActorInterface

extend the above

in the C++ constructor

RootComponent->SetMobility(EComponentMobility::Movable);

1 Like

Thanks Rama, this looks like what I’m after.

I’m having a problem extending from ANavModifierVolume though, I’m getting many linker errors (here’s a sample):

error LNK2001: unresolved external symbol "public: virtual bool __cdecl ABrush::IsLevelBoundsRelevant(void)const " (?IsLevelBoundsRelevant@ABrush@@UEBA_NXZ)	...MobileNavModifierVolume.cpp.obj


error LNK2001: unresolved external symbol "public: virtual void __cdecl ABrush::CheckForErrors(void)" (?CheckForErrors@ABrush@@UEAAXXZ)	...MobileNavModifierVolume.cpp.obj

I’m running off of the launcher version 4.4.1 at the moment. Do you know of any steps to remedy this?

I am having the same problem. I’ve already spent a week trying t modify costs on runtime…How did you solve it?

For my purposes, the NavModifierComponent is what I am using

I tried to override cost functions in the nav mesh but I found that so *** difficult…Are you spawning NavModifiers on runtime and changing its costs?
Do you know if a lot of nav modifiers can bring performance issues?
Finally I would be very happi if you can you show me a sample code instanciating your own Nav Modifier.

Thanks!

I’m placing movable actors with NavModifierComponents attached to them. The components take a NavArea class that defines the custom costs