Skip to content

On scene load, NavigationAgent2D has target 0,0 and is_navigation_finished() == false when there is more than one navigation layer set #101232

Closed
@bluefeversoft

Description

@bluefeversoft

Tested versions

System information

Godot v4.3.stable - Windows 10.0.26100 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 4070 SUPER (NVIDIA; 32.0.15.6603) - AMD Ryzen 7 3800X 8-Core Processor (16 Threads)

Issue description

I have attached a demo project.

If you have NavigationAgent2D with avoidance enabled and have either:

  • any navigation layer selected apart from layer 1
  • multiple navigation layers selected

they are by default "navigating" when first created even though no target has been set.

In other words, navigation_agent_2d.is_navigation_finished() == false

If layer 1 is selected, navigation_agent_2d.is_navigation_finished() == true, which is correct as no target has been set yet.

Steps to reproduce

The setup:

  • created a main test scene
  • added a NavigationRegion2D with a NavigationPolygon, set to Navigation Layers 1

Image

  • made a new Node2D scene, added a Sprite2D and a NavigationAgent2D, enables Avoidance and connected the velocity_computed signal

Image

  • add this to the scene:
extends Node2D

@onready var navigation_agent_2d: NavigationAgent2D = $NavigationAgent2D

func _ready() -> void:
	print("_ready:", navigation_agent_2d.is_navigation_finished())
	set_physics_process(false)
	print("_ready2:", navigation_agent_2d.is_navigation_finished())
	call_deferred("late_init")
	print("_ready3:", navigation_agent_2d.is_navigation_finished())


func late_init() -> void:	
	print("late_init:", navigation_agent_2d.is_navigation_finished())
	set_physics_process(true)


func _physics_process (delta: float) -> void:	
	pass

func _on_navigation_agent_2d_velocity_computed(safe_velocity: Vector2) -> void:
	pass

Added the ship to the main:

Image

And running gives this:

Image

This is expected.

But, if I then set the ship navigation layers to 2 as well

Image

The output running the game is

Image

So it has a state of not yet finished navigating, which is odd as I only changed the layer.

If I select layer 2 only:
Image

Then the output is also false:

Image

Is this expected?

I know we can set a target instantly, but I was sent down a bit of a rabbit hole today wondering why my sgents wouldn't move when more than one layer was set :)

If I am being an idiot here, I am really sorry.

Minimal reproduction project (MRP)

Here is the project, I hope it's enough for you to go one.

Nav.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions