+1 vote

I created a mesh library and also a gridmap to place the mesh procedurally using code.
Now,I want to loop through all the mesh instance in my scene and edit their properties using code seperately.
Btw,get_meshes() is not what i want,because it returns the mesh and the transformation,not the individual created objects.

As an alternative,is it better to abandon using gridmap and use mesh instancing manually instead?

And also how do I let user interact with meshes in mesh library in grid map?
Ive tried using signal,but it doesnt seem to work in gridmap.

in Engine by (46 points)
edited by

1 Answer

+1 vote
Best answer

GridMap does not really create individual MeshInstance nodes, you won't be able to loop through them all in this way. What GridMap allows is only to change their orientation by 90 degree steps, change wich one is placed in each cell, and show or hide them.
You can modify the meshes it uses, but that will apply to every usage of the said mesh within the gridmap, because it's not individual tiles, they are re-used and batched.

If you want to arrange meshes in a grid AND modify them individually at runtime, you should make the grid yourself either with MeshInstance or MultiMesh.

And also how do I let user interact with meshes in mesh library in grid map?
Ive tried using signal,but it doesnt seem to work in gridmap.

Blocks of a GridMap can have collision shapes, when you make the mesh library. However, you won't be able to tell "this collision occurred with this particular node", because again, GridMap doesn't create nodes. However, (like TileMap in 2D), you may be able to tell which grid position you collided with, using world_to_map: https://docs.godotengine.org/en/stable/classes/class_gridmap.html#class-gridmap-method-world-to-map
This then lets you call get_cell to find out which type of block you collided with. get_cell returns an ID which you can use in most MeshLibrary functions: https://docs.godotengine.org/en/stable/classes/class_meshlibrary.html#class-meshlibrary

by (28,791 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.