Serialize instance of object when saving

Hello,

I create all my meshes with classes and i’d want to serialize the instances of these objects when saving my scene.

It does not work because of a loop when serializing. https://playground.babylonjs.com/#NKJY38#2

Is it possible to do such things ?

Thanks for your answers.

Boris

1 Like

as the error message explains you are creating a circular reference by placing your mesh in the metadata : box.mesh.metadata.instance = box

The mesh will serialize and try to serialize box through metadata which serialize your mesh and so on…

If you wrap your meshes in your own structure, you should not serialize the scene but your own structure with enough info to recreate it when you parse it.

2 Likes

Ok, i think i will be too difficult.

I will set only the name of the class in the mesh metadata and recreate an object from the mesh when loading my scene.

2 Likes