Connecting to NavigationServer "map_changed" signal

Godot Version

4.3 stable

Question

I am trying to connect to NavigationServer3D’s map_changed signal.
(NavigationServer3D — Godot Engine (stable) documentation in English)
but I get an error “Signal is nonexistent” (while I managed to connect the on_ready signal through the current method - see code below).
I resorted to using a code connect, since the NavigationServer is not a Node (afaik) and then does not appear in the editor signals list of my test scene.

It probably comes from the fact I should somehow pass the map’s RID (as it is a param mentionned in the linked doc) while connecting, but I can not think of how to do so.

using Godot;
using System;

public partial class ExampleNavigationRegion : NavigationRegion3D
{
	private void OnTreeEntered()
	{
		GD.Print("ExampleNavigationRegion entered Tree");
		this.Connect(ExampleNavigationRegion.SignalName.Ready, new Callable(this, MethodName.OnReady));
		this.Connect(NavigationServer3D.SignalName.MapChanged, new Callable(this, MethodName.OnMapChanged));
	}
	private void OnReady()
	{

		GD.Print("Ready");
	}
	private void OnBakeFinished()
	{
		GD.Print("baking finished");
	}
	private void OnNavigationMeshChanged()
	{
		GD.Print("Navigation Mesh changed");
	}
	private void OnMapChanged()
	{
		GD.Print("Navigation Map changed");
	}
}

You do not need to pass a map RID to connect but the function to receive the signal callback needs a RID parameter as that is what gets send.

1 Like

Someone pointed me to the more modern way of connecting and it worked :smiley:

NavigationServer3D.Singleton.MapChanged += OnMapChanged;
//this.Connect(NavigationServer3D.SignalName.MapChanged, new Callable(this, MethodName.OnMapChanged));

indeed @smix8 the callable needs its Rid param, but even with this fixed it would still spit the error as long as I would use the Connect alternative.

	private void OnMapChanged(Rid map)
	{
		GD.Print("Navigation Map changed");
	}

Sure but you should always check against the RID. You wouldnt know which map is synced without checking the region map RID against the map RID. Could be a 2d map that was synced while your 3d map was not processed. They all share the same server and the server sends this signal out for any map that gets synced.

1 Like

After looking into it further, correct Connect use would be :

NavigationServer3D.Singleton.Connect(NavigationServer3D.SignalName.MapChanged, new Callable(this, MethodName.OnMapChanged));

@smix8 indeed, ill make sure to follow your advice. Thanks!