Godot Version
godot-4.3-stable
Question
So I'm trying to make a game with blocky terrain (kind of like Minecraft, but hexagonal instead of square) I have the terrain chunks being created as array meshes in a separate thread, but for some reason it freezes the main thread until they can load in. Is there some other way that I have to do this?
What does your code look like?
Do you need the whole thing or just the threading code?
Just how you are hanlding the thread(s) I suppose.
#I put this at the top:
var thread : Thread
#Function to call the thread. This function is called by the parent node of all the chunk meshes:
func generate():
position.x = chunk_x * 13.44
position.z = chunk_z * 16
thread = Thread.new()
make_solid_chunk()
thread.start(Callable(self, "generate_mesh"))
Are you sure it’s this generate function that halts? Assuming you call generate within _ready maybe the act of loading the chunk nodes is heavier than generating?
Well, the node is just an empty MeshInstance3D when it gets added as a child… The script to load the chunk then gets immediately called by the parent node.
Start by commenting out all calls in the thread code that communicate with the scene tree or send vertex data to gpu.
How many threads do you launch at the same time?
What does the profiler say about the spike(s)?
Now that’s odd… It shows the ‘generate’ function as lasting as long as the thread does…
Figured it out: the function for setting up the mesh was not inside the thread. LOL. Thanks to both of you for your help!