-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[NavigationAgent2D/3D]: target_reached signal is emitted before internal state is updated #67939
[NavigationAgent2D/3D]: target_reached signal is emitted before internal state is updated #67939
Conversation
Needs a dedicated backport to 3.x, only the 2D part: godot/scene/2d/navigation_agent_2d.cpp Lines 481 to 488 in 33b80bd
3D is fine in there (for whatever reason 😆): godot/scene/3d/navigation_agent.cpp Lines 492 to 499 in 33b80bd
|
Makes sense to me. Thanks and congratulations on your first merged contribution! |
@kleonc about the backport, is this something that will be done at some point or is it expected I create a new PR targetting 3.x branch? In the pr_workflow document it says
For me it's fine either way, whatever is easiest for you 👍 |
@sambriels Actually I haven't added any |
When using a
NavigationAgent2D
orNavigationAgent3D
the signal that gets emitted once the agent has reached its target (target_reached
) is sent before the internal state is properly updated.Namely, the
target_reached
property of the agent will be overridden once the signal has been processed. When listereners to the signal try to issue a new target, as in:its internal state is (correctly) reset, but directly thereafter the
target_reached
property is set totrue
again. Thistrue
is based on the old target, not the new one, and thus the agent enters a corrupt state where it thinks it reached it's target but it actually hasn't.The solution is to delay the emission of the signal until the internal state has been changed. Which also makes sense since the actual reaching of the target should only complete once the internal representation is reflecting that.
I don't see any downsides to delaying the emission of the signal, and since all the tests still pass I assume this change can be safely made. I've attached a minimal reproduction project and two gifs from its execution before and after the change
minimal_repro_project
current_behaviour.webm
expected_behaviour.webm