Pathfinding 3D procedural terrain

Godot Version

4.3 stable official

Question

I’m following along with the navigation mesh script template on the docs which details how to update a navigation region with procedurally generated mesh data.

(see bottom of the page) (Using navigation meshes — Godot Engine (stable) documentation in English)

Run into an issue, namely calling NavigationServer3D.region_set_map(region_rid, get_world_3d().get_navigation_map()) where get_world_3d() is returning null.

The .gd class I’m calling it from extends MeshInstance3D should that matter.

The Viewport did not even have enough time to init its World3D ref or the node from where you called the script was not in the SceneTree / did not join the world.

So whatever you do don’t do it in the init() phase or on a thread on the very first frame. You need to give the SceneTree some time to setup at least the basics.

nah it’s all good. The generate_terrain method was being called prior to the chunk being added as a child to its parent object.

func create_chunk_at_index(x, y) -> void:		
	var chunk : Chunk = chunk_prefab.instantiate()
	chunk.set_pos(Vector3(x * Chunk.SIZE, 0, y * Chunk.SIZE))
	chunk.generate_terrain(noise)
	add_child(chunk)

became

func create_chunk_at_index(x, y) -> void:		
	var chunk : Chunk = chunk_prefab.instantiate()
	add_child(chunk)
	chunk.set_pos(Vector3(x * Chunk.SIZE, 0, y * Chunk.SIZE))
	chunk.generate_terrain(noise)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.