Sphere
Log in Join
☆ 2

NavigationAgent2D recalculates the path every frame

My enemies call get_next_path_position every frame and I also set target_position every frame. Profiler shows pathfinding as a hot spot.

⚑ Report

3 replies

☆ 0
C Chris ·2026-10-16#1

Only set target_position when the target actually changes. Setting it each frame can trigger a replan.

⚑ Report
☆ 0
A Alex ·2026-10-16#2

I changed that. Now agents sometimes walk into walls when the player moves.

⚑ Report
☆ 0
F ferretpixel42 ·2026-10-17#3

Add a replan interval, for example every 0.3 seconds, and set path_desired_distance so they do not repath at every tiny movement. Also check collision layers on the navigation region.

⚑ Report
Log in to reply.