Jump to content

SceneSerializer doubles the count of material and texture


Recommended Posts

Load a scene from a file, serialize it and count the number of materials in  the serialized string.

You will see that the material count in the string is double the count in the file.

Serialization doubles the count.

I checked the code and I think it has to do with the way the loader and serializer work together.

Loader, while loading,  loads  each material in the file as  StandardMaterial into the scene.

The Serializer while serializing adds all the material in the scene to the JSON object and then adds the material again if it is StandardMaterial - effectively doubling the count.


I am working on an app which allows the user to serialize and save the scene to a file and I noticed that over subsequent saves the file kept getting bigger and bigger even though no changes were made to the scene, which is when I started looking into this issue.



Link to comment
Share on other sites

I will try and reproduce it in the playground today

I am not appending the scene. I am just loading the scene from a file.

the loader loads each material as standard material, that is for each material in the file it creates a standard material and then set its property to that found in the file

the serializer ends up loading each material from the scene into the serialization object twice as follows.

 It first loads all the materials into the serialization object then goes through the list of material one more time, this time checking if it is a standard material and if it finds it to be so then it loads it again into the serialization object. Thanks to the loader each material is a standard material and thus gets loaded twice.

Link to comment
Share on other sites

Looks like the problem might have been solved in 2.3

I tried reproducing this in playground but failed. Then I noticed that playground has switched to 2.3

Check this out


See if you can run this in 2.2

You will see different result then.

The example linked above is a simple example

It creates one additional material.

It then prints out the number of materials in the scene. 

it then serializes the scene and then prints out the number of materials in the serialized object

In 2.2 the count show up as 2 and 4

In 2.3 the count show up as 2 and 2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...