MakePolygonsFromOutlines is depreceated, how do i setup the nav region now?

Godot Version

4.2

Question

I updated my project to Godot 4.2, now it says the MakePolygonsFromOutlines is depreceated, what do i use know? i tryed use the NavigationServer2D.BakeFromSourceGeometryData and NavigationServer2D.ParseSourceGeometryData but i dont know if i need use both or when use both, it also broke my pathfind system.

You can still use the deprecated function. The main reason the function still exists is so older projects that rely on the old outline bake behavior can finish what they started.

Switching to the new baking might not always be possible with old scenes when they had NavigationPolygon with nested, inner outlines all stacked in the same polygon resource. You can the updated documentation for the new 2D navigation mesh baking here: Using navigation meshes — Godot Engine (latest) documentation in English

Well on my scene its possible, iam making a game like Clash Royale, so i make a big isometric Square around the map with navigation polygon, but for some reason when i switch to bake the area be smaller and be on wrong position, idk why

The NavigationPolygon has by default an agent radius of 10 pixel to match the NavigationAgent2D radius. That agent radius shrinks the polygon surface when baking. This offset is done because when navigation mesh and physics collision align without margin agents get stuck, especially at corners. If you don’t need or want the offset set the agent radius to zero.

well i did all the way the tutorial but still not work

NavigationMeshSourceGeometryData2D geometryData2D = new NavigationMeshSourceGeometryData2D();

		geometryData2D.AddTraversableOutline(points);

		NavigationServer2D.ParseSourceGeometryData(pathfindRegion.NavigationPolygon,geometryData2D,pathfindRegion);
		NavigationServer2D.BakeFromSourceGeometryData(pathfindRegion.NavigationPolygon,geometryData2D);

        Rid region2D = NavigationServer2D.RegionCreate();
		NavigationServer2D.RegionSetNavigationPolygon(region2D,pathfindRegion.NavigationPolygon);
		NavigationServer2D.RegionSetEnabled(region2D,true);
		NavigationServer2D.RegionSetMap(region2D,pathfindRegion.GetRid());

That was before btw

geometryData2D.AddTraversableOutline(points);

NavigationServer2D.ParseSourceGeometryData(pathfindRegion.NavigationPolygon,geometryData2D,pathfindRegion);

The parsing function will clear the existing data so that traversable outline that you add here will not exist.

NavigationServer2D.RegionSetMap(region2D,pathfindRegion.GetRid());

If that is not a navigation map RID masquerading as a region that will not work. You are setting a region to a region.

so how do i make it right?can you show me

The examples are part of the documentation page that I linked earlier.

But i dos exactly like the examples and didnt work :confused:


its working now but my pathfind stop work, monsters doenst walk anymore :confused:

NavigationServer2D.ParseSourceGeometryData(pathfindRegion.NavigationPolygon,geometryData2D,pathfindRegion);

        geometryData2D.AddTraversableOutline(points);

		NavigationServer2D.BakeFromSourceGeometryData(pathfindRegion.NavigationPolygon,geometryData2D);

Monsters

public override void _Ready()
	{
		range = FindChild("Range").GetChild<CollisionPolygon2D>(0);
		body = GetChild<CollisionPolygon2D>(0);

        navigationAgent = new NavigationAgent2D
        {
            AvoidanceEnabled = false,
			DebugEnabled = true,
			AvoidanceLayers = 2,
			AvoidanceMask = 3,
			AvoidancePriority = 1,
			Radius = bodySize
        };

		AddChild(navigationAgent);

		navigationAgent.VelocityComputed += OnVelocityChanged;

        SetupBody();
		SetupRange();
	}


public override void _Process(double delta)
	{

		if (!battling) return;
		if (target != null) return;

		target = getTarget();
		navigationAgent.TargetPosition = target.BuildingPosition;
	}

    public virtual void OnVelocityChanged(Vector2 newVelocity){
		Velocity = newVelocity;

		MoveAndSlide();
	}

	public override void _PhysicsProcess(double delta)
	{
		if (inRange)
		{
			Velocity = Vector2.Zero;
			MoveAndSlide();
			return;
		}
		if (target == null) return;

		Vector2 dir = ToLocal(navigationAgent.GetNextPathPosition() + newVelocity).Normalized();
		navigationAgent.Velocity = dir * speed;
	}