NavigationServer2D.map_get_random_point doesn't randomize the pathway

Godot Version

godot-4.5

Question

Here’s part of my walkable chicken code:

func _ready() -> void:    
    randomize()
    call_deferred("character_setup")    

func character_setup() -> void:
    await get_tree().physics_frame
    set_move_target()

func set_move_target() -> void:

    var target_pos: Vector2 = NavigationServer2D.map_get_random_point(
        nav_agent.get_navigation_map(),
        nav_agent.navigation_layers,
        false)
    
    nav_agent.target_position = target_pos
    speed = randf_range(min_speed, max_speed)

func physics_process(_delta: float) -> void:

    if nav_agent.is_navigation_finished():
        next_transition()       
        return

    var target_pos: Vector2 = nav_agent.get_next_path_position()
    var target_dir: Vector2 = character.global_position.direction_to(target_pos)
    anim_sprite.flip_h = target_dir.x < 0
    character.velocity = target_dir * speed
    character.move_and_slide()

But when you start the game, all the characters always go to the same point, although the author video everything is fine, my code is the same as his, only the name of the variables is changed and some functions that do not affect this. Please help.

If they’re always walking to global (0, 0), that would be the NavigationAgent’s default target position. In that case, you should use print statements or breakpoints to check if set_move_target() is getting called and what values target_pos and nav_agent.target_position have.

Thank you very much, I really didn’t notice that I forgot to call this method initially.