Tested versions
- Reproducible in Godot 4.5.1 stable
System information
Windows 10 - Godot 4.5.1 - GTX970
Issue description
Copied from Reddit where I raised the issue:
Post
I am not sure whether to consider this a bug or not, but there is one kind of weird behavior I am experiencing when working with a level geometry from .blend file.
Basically imagine you have a box model in blender scene.
You name it box.001 -col for it to have collision in the godot scene.
It works as it should.
Then in Blender you create a linked duplicate = ALT+D and name it box.002 - without the -col suffix!
Now the weird thing:
In godot scene using the .blend scene for level geometry - box.002 will have collision! At first I thought that it was a feature. That in Godot the connection between box.001 and 002 is kept.
BUT - if I restart the project in Godot all those linked duplicates that previously had functional collisions in Godot suddenly don't have them at all.
Reply by user GCW237:
You are right, importing linked duplicates does seem to behave like this. I recommend that you open an issue on Godot github to confirm whether this is a bug or should be better documented.
The problem, I think, stems from how resource_importer_scene.cpp handles importing of mesh with collision hints. Specifically, if we look at 786 to 800:
if (mi) {
Ref<ImporterMesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Vector<Ref<Shape3D>> shapes;
if (r_collision_map.has(mesh)) {
shapes = r_collision_map[mesh];
} else if (_teststr(name, "colonly")) {
_pre_gen_shape_list(mesh, shapes, false);
r_collision_map[mesh] = shapes;
} else if (_teststr(name, "convcolonly")) {
_pre_gen_shape_list(mesh, shapes, true);
r_collision_map[mesh] = shapes;
}
If I understand correctly, when importing meshes, the importer creates a map from mesh to collision shapes, not from name to shapes (likely to avoid naming conflicts). And since the linked duplicates share the same underlying mesh instance, what most likely happened was:
importer sees box.001 -col, creates a collision and maps it to the underlying mesh.
importer sees box.002, checks whether any collision is mapped to its mesh, and indeed box.002 has the same mesh as box.001 -col, so it grabs that collision and puts it on box.002.
As for why the collision disappeared after reopening the project–I am too lazy to read more source codes, but I suspect that when loading from a saved scene, the import process is different, whether it be a different ordering of importing meshes or skipping the collision shape mapping entirely. But there is something different that resulted in the linked duplicates no longer sharing the collision.
As for now, I think it is better to not importing linked duplicates to avoid headaches down the road. And again, I doubt this behavior is expected and recommend reporting an issue to the core engine people
Steps to reproduce
-
create a .blend scene in Blender
-
in it create an object box.001 and rename it to box.001 -col
-
create an linked copy of box.001 by ALT+D function
-
name it box.002
-
save and import the .blend file into the Godot project
-
observe that both box.001 and box.002 have a collision mesh)
-
while the Blender and Godot are running you can also create another linked copy - box.003 in blender and save the scene to observe after automatic reimport in godot box.003 will also have collision mesh
-
Save the Godot scene and exit the program
-
Run Godot again and open the project
-
observe that both box.002 and box.003 now don't have collision meshes
Minimal reproduction project (MRP)
N/A
Tested versions
System information
Windows 10 - Godot 4.5.1 - GTX970
Issue description
Copied from Reddit where I raised the issue:
Post
I am not sure whether to consider this a bug or not, but there is one kind of weird behavior I am experiencing when working with a level geometry from .blend file.
Basically imagine you have a box model in blender scene.
You name it
box.001 -colfor it to have collision in the godot scene.It works as it should.
Then in Blender you create a linked duplicate =
ALT+Dand name itbox.002- without the-colsuffix!Now the weird thing:
In godot scene using the .blend scene for level geometry -
box.002will have collision! At first I thought that it was a feature. That in Godot the connection betweenbox.001and002is kept.BUT - if I restart the project in Godot all those linked duplicates that previously had functional collisions in Godot suddenly don't have them at all.
Reply by user GCW237:
You are right, importing linked duplicates does seem to behave like this. I recommend that you open an issue on Godot github to confirm whether this is a bug or should be better documented.
The problem, I think, stems from how resource_importer_scene.cpp handles importing of mesh with collision hints. Specifically, if we look at 786 to 800:
If I understand correctly, when importing meshes, the importer creates a map from mesh to collision shapes, not from name to shapes (likely to avoid naming conflicts). And since the linked duplicates share the same underlying mesh instance, what most likely happened was:
importer sees
box.001 -col, creates a collision and maps it to the underlying mesh.importer sees
box.002, checks whether any collision is mapped to its mesh, and indeedbox.002has the same mesh asbox.001 -col, so it grabs that collision and puts it on box.002.As for why the collision disappeared after reopening the project–I am too lazy to read more source codes, but I suspect that when loading from a saved scene, the import process is different, whether it be a different ordering of importing meshes or skipping the collision shape mapping entirely. But there is something different that resulted in the linked duplicates no longer sharing the collision.
As for now, I think it is better to not importing linked duplicates to avoid headaches down the road. And again, I doubt this behavior is expected and recommend reporting an issue to the core engine people
Steps to reproduce
create a .blend scene in Blender
in it create an object box.001 and rename it to box.001 -col
create an linked copy of box.001 by ALT+D function
name it box.002
save and import the .blend file into the Godot project
observe that both box.001 and box.002 have a collision mesh)
while the Blender and Godot are running you can also create another linked copy - box.003 in blender and save the scene to observe after automatic reimport in godot box.003 will also have collision mesh
Save the Godot scene and exit the program
Run Godot again and open the project
observe that both box.002 and box.003 now don't have collision meshes
Minimal reproduction project (MRP)
N/A