godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.54k stars 21.26k forks source link

Reimporting saved-to-file meshes removes materials #79779

Open leonardschardijn opened 1 year ago

leonardschardijn commented 1 year ago

Godot version

v4.2.dev1.official [0c2144da9]

System information

Arch Linux

Issue description

If you extract as Resources (save to file) the meshes from a glTF file, and use those meshes in MeshInstance3D nodes, when you reimport the glTF file all assigned Materials will be removed from your MeshInstance3D nodes.

Steps to reproduce

Steps to reproduce the issue in the Minimal reproduction project:

  1. Open the mesh_instance_3d.tscn Scene. The MeshInstance3D node is using the cube_mesh.res Resource extracted from the cube.glb glTF file. There is a Material assigned to the _surface_materialoverride (surface 0) property.
  2. Open the cube.glb file and click Reimport.
  3. The assigned material in _surface_materialoverride is now gone.

NOTES: If you close the project and reopen it, the Material will be back. If you save the project (even if there is no * indicating a modification), the Material is gone for good.

Minimal reproduction project

import_bug.zip

OhiraKyou commented 7 months ago

Still seeing this on v4.2.2.stable.official [15073afe3], despite PR 85922 being included.

Problematic setup

I have a .glb file in the project whose mesh is automatically extracted, on reimport, to a subdirectory (using the usual mesh paths feature of the advanced import window). A MeshInstance3D in an opened scene references the extracted mesh. And, that scene is instantiated in the world scene.

When I export the .glb file from Blender (triggering mesh extraction), the surface material override is cleared in the MeshInstance3D inspector. The 3D viewport still appears to render the old material. But, playing the parent world scene reveals that the material is not assigned.

Workaround

My current workaround is to make the mesh instance a child of yet another scene that is kept closed. As long as the MeshInstance3D's direct parent scene isn't open during reimport, there seems to be no risk of the references breaking and those breakages being saved. Opening the scene after a reimport reveals that the material reference is still intact.

MajorMcDoom commented 6 months ago

I get this issue on 4.3.dev6 and 4.3.beta1

MajorMcDoom commented 3 months ago

Just adding some more data for whoever tackles this issue:

This bug also occurs if you use an import script to, say, extract multiple meshes from a single .blend file. Or if you build new .scn assets from the .blend file without directly creating a mesh asset.

That is, I believe the bug isn't on the importing side, but in whatever is handling the "refresh" of currently loaded MeshInstance3Ds.

I also have noticed that the mesh data itself also sometimes does not refresh properly (it keeps displaying an outdated mesh after reimport), which could be related, although I don't have a proper repro yet.

SubhadeepJasu commented 1 month ago

Also happens when importing obj mesh.