Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
5
Question by $$anonymous$$ · Feb 21, 2017 at 07:17 PM · serializationjsoninstances

JSON Serialization and Instance IDs

I want to use ScriptableObjects as data containers that I will serialize with JSONUtility.
However references to GameObjects, MonoBehaviours or other ScriptableObjects are represented with an instance id in the resulting json file.
Can Unity properly hook up the correct instance if I deserialize the Object?
What about GameObjects that were created at runtime?

Comment
Add comment · Show 4
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 LavaPatrik · Apr 20, 2017 at 04:17 PM 0
Share

I'm struggling with the exact same issue.

 using UnityEngine;
 
 public class SerializerTest
 {
     public SerializerTest()
     {
         SimpleTest();
         AdvancedTest();
     }
 
     void SimpleTest()
     {
         var foo = ScriptableObject.CreateInstance<Foo>();
         foo.Number = 32;
         Debug.Log(JsonUtility.ToJson(foo, true));
     }
 
     void AdvancedTest()
     {
         var firstFoo = ScriptableObject.CreateInstance<Foo>();
         firstFoo.Number = 32;
 
         var secondFoo = ScriptableObject.CreateInstance<Foo>();
         firstFoo.Number = 16;
 
         var bar = ScriptableObject.CreateInstance<Bar>();
         bar.String = "testing";
         bar.AFoo = firstFoo;
         bar.BFoo = secondFoo;
 
         Debug.Log(JsonUtility.ToJson(bar, true));
     }
 
     public class Foo : ScriptableObject
     {
         public int Number;
     }
 
     public class Bar : ScriptableObject
     {
         public string String;
         public Foo AFoo;
         public Foo BFoo;
     }
 }

Results in:

 {
     "Number": 32
 }

and

 {
     "String": "testing",
     "AFoo": {
         "instanceID": -297306
     },
     "BFoo": {
         "instanceID": -297308
     }
 }

I'm trying to sync stuff over network, and obviously those "instanceID"'s won't work!

avatar image Hellium · Jan 31, 2018 at 02:43 PM 0
Share

I'm bumping the question because I'm facing the same issue.

avatar image Noxury · Aug 25, 2018 at 10:29 AM 1
Share

Also have this problem. Im saving a list of ScriptableObjects, that I use for an EditorWindow, but get also their InstanceIDs in the JSON-File.

avatar image eses Noxury · Aug 25, 2018 at 12:43 PM 0
Share

@Noxury - It might not be suitable in your case, but I've just used separate C# serializable classes to contain data I need. Before serialization, collect the ScriptableObject data to these data classes, then serialize these. When deserializing do the opposite. But I've worked very little with serialization yet.

0 Replies

· Add your reply
  • Sort: 

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

69 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Best Way to Store Large Number of GameObjects? 1 Answer

unity 3d loading data from json problem?! 1 Answer

JSON - Load Subset of Files Based on Key in File 0 Answers

MiniJSON Multiple Rows 1 Answer

JsonUtility not found / working 0 Answers


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