The Problem
I was recently messing around with GridMap
s in Godot Engine which allow you to "paint" meshes on a 3D grid much like you would a 2D tileset. Following the official GripMap
tutorial, I noticed some odd behavior creating a MeshLibrary
.
I was using the models from the City Kit Roads pack from Kenney.nl. They render nicely in the scene tree, but when using the Scene -> Convert to MeshLibrary
option to create a MeshLibrary
the resulting .tres
file was empty. In previous projects, this feature has worked for me so I wondered if there was something particular about these assets that was missing something Godot expected.
The Investigation
I've had luck looking at the Godot source code, in other situations, thanks to it being open source. A quick look at the MeshLibrary
code showed something worth looking into:
mesh_library_editor_plugin.cpp#L78-L88
void MeshLibraryEditor::_import_scene(Node *p_scene, /* ... */) {
// ...
for (int i = 0; i < p_scene->get_child_count(); i++) {
Node *child = p_scene->get_child(i);
if (!Object::cast_to<MeshInstance3D>(child)) {
if (child->get_child_count() > 0) {
child = child->get_child(0);
if (!Object::cast_to<MeshInstance3D>(child)) {
continue;
}
} else {
continue;
}
}
// ...
Here the _import_scene()
function is looping over the scenes children and if they are not a MeshInstance3D
then it looks at the first grandchild, if there are no grandchildren or the first one isn't a MeshInstance3D
then it skips the whole child. That seemed promising, so I opened the asset as a "New Inherited Scene" and sure enough it was nested.
The Solution
A quick edit as a "New Inherited Scene" to change the hierarchy like this
And the models were added to the MeshLibrary
without issues.
Top comments (0)