Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by frarees · May 08, 2013 at 04:14 PM · serializationlibraryserializemessagedeserialization

When OnDeserialized (UnitySerializer) is meant to be called?

I'm using UnitySerializer 2.48, downloaded from here. Using JSON deserializer.

As it's documented on it's website:

Every script that is loaded can contain an OnDeserialized() function that will be called after the level has been loaded and before it starts to run. This function is exactly like the normal Unity functions and can be private or public as you wish. You would use it to do any final initialization.

From the first line, I interpret that it should be called for every object that has been potentially loaded, however, the code that seems responsible for this is:

     internal static void InvokeDeserialized()
     {
         _suspensionCount = 0;
         if (Deserialized != null)
         {
             Deserialized();
         }
         foreach (var go in UnityEngine.Object.FindObjectsOfType(typeof (GameObject)).Cast<GameObject>())
         {
             go.SendMessage("OnDeserialized", null, SendMessageOptions.DontRequireReceiver);
         }
     }

AND, the only call to this method is commented:

 //Tell the world that the level has been loaded
 //LevelSerializer.InvokeDeserialized();

So, not a GameObject is noticed at all.

However, the way I interpret the self-descriptive OnDeserialize name, it makes me think that every deserialized GameObject (those having a StoreInformation or derived component) should get an OnDeserialized message sent to each component on it, just after it has been deserialized.

The thing is that currently I only get OnDeserialized messages when an object that has been saved/serialized is not present on the scene when is first loaded. That is, marking a GameObject on the scene with a StoreInformation or derived, running the game, saving game state, stop running, delete that GameObject from scene, running again, and loading previously saved game state.

The code related to this "message broadcasting" is listed here:

     //Flag that we aren't deserializing
     foreach(var obj in flaggedObjects)
     {
         obj.IsDeserializing = false;
         obj.SendMessage("OnDeserialized", SendMessageOptions.DontRequireReceiver);
     }

Is the way it's currently working the proper way? Am I misunderstanding something?

In case it works as it should, how can I get notified when an Object has been deserialized? I want a way to serialize my managers, and want them to be deserialized following a kind of priority, so that my managers get deserialized after each of the other objects I want to de/serialize.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image frarees · May 08, 2013 at 06:39 PM 0
Share

@whydoidoit do you think you could help me here?

avatar image frarees · May 09, 2013 at 09:44 AM 0
Share

@whydoidoit there's an inconsistence between how LevelLoader and JSONLevelLoader send the OnDeserialized message. The former does send it when an object is deserialized (good), but the latter only does that when the object does not initially exist on the scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by frarees · May 09, 2013 at 10:06 AM

I've spotted a bug that's found on UnitySerializer 2.48, causing OnDeserialized messages not to be sent properly for JSON level loader.

Add this after line 198 in JSONLevelLoader.cs:

 flaggedObjects.AddRange(Data.StoredObjectNames.Select(c=>UniqueIdentifier.GetByName(c.Name)).Where(c=>c!=null).Select(c=>c.GetComponent<UniqueIdentifier>()));
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Remigino · Jun 16, 2013 at 09:52 PM 0
Share

Thank you so much this was very helpful and fixed the same problem i was having.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fast, easy serialization library for Unity? 0 Answers

Serialize the text 2 Answers

Serialized data show information after load 0 Answers

How to serialized a variable in a c# method? 1 Answer

Unity still references file moved to different folder 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges