Serialized object then reload without material

Hello,

When you serialize an object and then this serialized object is reloaded, the material is lost.
In the inspector in “Active Material”, the material has become Default Material

Scene with the BoomBox and its texture
https://www.babylonjs-playground.com/#WGZLGJ#4725

Another scene with a simple sphère and a texture
https://www.babylonjs-playground.com/#WGZLGJ#4727

On my project, I save in a file the mesh modified via the inspector. But when this file is reloaded, the mesh is transparent, more textures, more material.

This is expected as the SerializeMesh function will only serialize the mesh
To serialize the mesh and all it needs to render you need to serialize the scene (BABYLON.SceneSerializer.Serialize(scene))

I don’t want to serialize the whole scene, just the meshes independently.
I rebuild the files of meshes modified by the inspector. Serializing the scene will create a file for me with all the meshes, camera lights… I wouldn’t want to do that.

It worked like this before. Is this a change? Why the material could not be serialized too. I do not understand.

I don’t think it ever worked like that(you can try your PG in 4.2 for instance)

If it worked like this before.

I just tried in the PG with version 4.2.0, 4.0.3 and the material was serialized

In fact the material seems to be serializing, but is not correctly reloading.

When we look at this PG, the material is serialized, but the inspector does not load it, but it is present in the lists.

I tried all the previous versions and it works normally. It’s only in version 5 that this happens.

looks like this PR might be the culprit Serialization: Use unique IDs for materials and multimaterials by darraghjburke · Pull Request #11734 · BabylonJS/Babylon.js · GitHub

The fix is available here Fix babylon mesh parsing, materials were not reattached. by sebavan · Pull Request #12370 · BabylonJS/Babylon.js · GitHub and will be in the next nightly

3 Likes

Fix is testable online:

https://babylonsnapshots.z22.web.core.windows.net/refs/pull/12370/merge/index.html#WGZLGJ#4725
and
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/12370/merge/index.html#WGZLGJ#4727
and
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/12370/merge/index.html#WGZLGJ#4728

2 Likes

Thank you very much Sebavan.

1 Like

Good catch seb! I missed it completely:)

1 Like