# Serialized object then reload without material

**URL:** <https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193>\
**Category:** Bugs\
**Created:** [April 8, 2022, 6:59pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193 "2022-04-08T18:59:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 8, 2022, 6:59pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/1 "2022-04-08T18:59:43Z")

</div>

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](https://www.babylonjs-playground.com/#WGZLGJ#4725)

Another scene with a simple sphère and a texture  
[https://www.babylonjs-playground.com/#WGZLGJ#4727](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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 9, 2022, 1:35am UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/2 "2022-04-09T01:35:19Z")

</div>

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)`)

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 9, 2022, 12:26pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/3 "2022-04-09T12:26:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 9, 2022, 1:00pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/4 "2022-04-09T13:00:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 9, 2022, 1:44pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/5 "2022-04-09T13:44:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 9, 2022, 3:52pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/6 "2022-04-09T15:52:11Z")

</div>

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.

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#WGZLGJ%234728)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 9, 2022, 7:21pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/7 "2022-04-09T19:21:06Z")

</div>

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](https://github.com/BabylonJS/Babylon.js/pull/11734/files#diff-b689b8bec44d2788ad3f5b9153b2dad822af0e6b0f51faf845e07b8e0ab65218)

The fix is available here [Fix babylon mesh parsing, materials were not reattached. by sebavan · Pull Request #12370 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/12370) and will be in the next nightly

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 9, 2022, 8:18pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/8 "2022-04-09T20:18:04Z")

</div>

Fix is testable online:

[https://babylonsnapshots.z22.web.core.windows.net/refs/pull/12370/merge/index.html#WGZLGJ#4725](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](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](https://babylonsnapshots.z22.web.core.windows.net/refs/pull/12370/merge/index.html#WGZLGJ#4728)

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 9, 2022, 9:00pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/9 "2022-04-09T21:00:40Z")

</div>

Thank you very much Sebavan.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 11, 2022, 1:38pm UTC](https://forum.babylonjs.com/t/serialized-object-then-reload-without-material/29193/10 "2022-04-11T13:38:12Z")

</div>

Good catch seb! I missed it completely:)
