Am I doing 3D Grid right?

Godot Version

4.3

Question

I created a scene called Cell. Here’s the cell. It’s a MeshInstance3D with the PlaneMesh type.

I created a scene called Chunk. Here’s the chunk. It’s 16 cells together with different coordinates.

I created a scene called Grid. Here’s the grid code. The scene is just a Node3D named Grid. I did this in code because I want to create a procedurally generated 3D grid.

I’m using the @tool thing to run the code in the editor.

The problem is that I’m having lag with just 9 chunks. Am I doing this right?

I know that there’s GridMap for that but I think I can’t attach a script to each cell with GridMap.

I want to, given a 2D array, where each position in the array holds a dictionary holding cell data, create a 3D grid through the code programmatically using data from the dictionary.

My end goal objective is to create an open world 3D grid. Like RimWorld, but 3D.

Thanks for any help in advance!

no. that will never work.

you are not assigning global_position to the instantiated nodes. also you are not supposed to add nodes from a tool script, it says so in the docs.
you are not adding nodes because you are not doing Engine.is_editor_hint() anywhere.
also it should be range(8) not range(0, 8).

8 times 8 is 64 times 16 is 1024 NODES. and that’s too many nodes.

for creating a voxel there’s a fork of the engine (that will continue to use the latest version of GODOT, so don’t worry it just adds features) called Voxel tools for godot

you read the docs and download the binaries and it’s a version of godot with voxel nodes.
It supports many different types of voxels, minecraft-like, subnautica-like, and also flat terrains. it recently added the ability to edit tiles.

it will give you a terrain to work on, it currently only supports one type of tile, but it is done correctly so it has good performance because the voxel is turned into a single mesh.
edit: correction, it supports different tile meshes with the blocky voxel, so that could be used to make buildings.

Check out GridMap

Your tool is creating 64 chunks (of 16 tiles? so 1024 total) objects on _ready() to the same location. I am pretty sure this scene setup limits GPU optimizations like instancing.


Adding nodes is allowed and great in @tool scripts

You can instantiate packed scenes normally and add them to the scene currently opened in the editor. By default, nodes or scenes added with Node.add_child(node) are not visible in the Scene tree dock and are not persisted to disk. If you wish the node or scene to be visible in the scene tree dock and persisted to disk when saving the scene, you need to set the child node’s owner property to the currently edited scene root.

Running code in the Editor

you are right, I was thinking of a warning not to use queue_free() and that altering the scene tree was dangerous.

1 Like

Thanks for all the answers!