Skip to content

NavigationAgent3D: Calling GetNextPathPosition during WaypointReached signal causes infinite recursion #91386

Closed
@TyberiusInSD

Description

@TyberiusInSD

Tested versions

-Reproducible in: v4.1.stable.mono.official [9704596], v4.2.stable.official [46dc277], v4.2.2.stable.mono.official [15073af], v4.3.dev5.mono.official [89f70e9]
-Not reproducible in: v4.0.stable.mono.official [92bee43]

System information

Godot v4.2.2.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated AMD Radeon RX 6900 XT (Advanced Micro Devices, Inc.; 31.0.21001.45002) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

Issue description

Connecting a method to the waypoint_reached signal of a NavigationAgent3D and calling navigation_agent.get_next_path_position() in said method causes an infinite recursion on the line that calls get_next_path_position().

For example, connecting the below method would cause a crash, but only if getPositionOnReach is set to true

func reached(_details: Dictionary):
	if getPositionOnReach:
		print(navigation_agent.get_next_path_position())
	else:
		print("No path position")

As a workaround, you can call "await get_tree().process_frame" before get_next_path_position() is called and it will work as expected.

This issue seems to have been introduced in v4.1.

I tested in v4.2 non-mono and it had the same error as well.

Steps to reproduce

  1. Create a NavigationAgent3D class like at the bottom of this page in the docs
  2. Connect a method to the navigation_agent.waypoint_reached signal which calls navigation_agent.get_next_path_position()
  3. Play the scene and get the error "Stack overflow (stack size: 1024). Check for infinite recursion in your script"

In C# there are no errors; the build opens, freezes for a moment, then closes itself.

In the MRP, I have included separate scenes for C# and GDScript. The GDScript scene can be run without a .NET build as far as I can tell, but I wanted to include C# specifically since there is no error shown for the crash which made it much more difficult to debug.

Minimal reproduction project (MRP)

Navigation3D MRP.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions