Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bluefeversoft opened this issue Jan 7, 2025 · 2 comments

Comments

@bluefeversoft
Copy link

bluefeversoft commented Jan 7, 2025

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, they are by default navigating when first created even though none has been set.

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

BUT

Only when you have two or more navigation layers selected.

If a single layer is selected all is ok, navigation_agent_2d.is_navigation_finished() == true

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

@smix8
Copy link
Contributor

smix8 commented Jan 7, 2025

If you set different navigation_layers than the default you are requesting a repath of the agent as part of the set_navigation_layers() setter function.

@bluefeversoft
Copy link
Author

bluefeversoft commented Jan 7, 2025

If you set different navigation_layers than the default you are requesting a repath of the agent as part of the set_navigation_layers() setter function.

Right! But this is in the IDE not in the code - so before I run the game.

The dynamic change in the code, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants