Help with baking a navigation polygon please

Godot Version

4.2.2, GDscript, 2d

Question

I am creating a game, and I’m using a NavigationRegion2D node for the navigation. I am not using a tilemap for the collisions or navigation, so when generating the world I have to bake the navigation polygon to the trees’(which are randomly placed) and other objects’ collision polygons. For this I am using the navigation region’s method: bake_navigation_polygon, but for some reason godot is giving the error: “Function “bake_navigation_polygon()” not found in base self.” Any help? Here’s the code for the navigation region:

extends NavigationRegion2D
signal  polygon_ready

func _on_world_tree_ready():
	var on_thread : bool = true
	bake_navigation_polygon(on_thread)
	
	polygon_ready.emit()

did you added node/spawn this NavigationRegion2D node into your main scene? or you just tell it to bake without ever init/construct it at very least?

I did add the NavigationPolygon to the NavigationRegion

i tested with a simple test like this:



no error
the polygon i made created before run, but no baking done:

if you do similar to this and still get the not found function, try screenshot more what you have and send here

Näyttökuva (14)

image
yeah not sure why your editor showing red line on that
what the error exactly said? copy and paste here

Function “bake_navigation_polygon()” not found in base self.

That error is misleading, if you have otherwise errors from e.g. garbled script parsing or failed scene loads in your project the script can not load the extends class and therefore does not find the function from that class. Fix the other errors or reload your project to fix script errors with e.g. class_names and other random stuff that may all be a source for this error.

It seems that the NavigationRegion doesn’t recognize other methods either, I think it’s probably from recently updating from 4.0 to 4.2. Any way to fix it?