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
2
Question by TowerOfBricks · May 12, 2011 at 04:30 PM · serializationloadsavingassetdatabase

How are unity references serialized? (instanceID related)

Hi

I'm building some serializing logic, and I'm trying to serialize a reference to a unityObject. What I have come across is AssetDatabase.GetAssetPath --> AssetPathToGUID. Which works quite well, but not for assets which aren't the "main" asset. And object.GetInstanceID --> EditorUtility.InstanceIDToObject which works even better.

But I wonder how references are serialized in the project by Unity, is it using InstanceIDs?

And is there a risk with using instanceIDs? Are they changed by Unity sometimes?

Lastly, is there a better way to serialize references?

Thanks, Aron

Comment
Add comment
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

2 Replies

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

Answer by almo · May 12, 2011 at 05:30 PM

This is not a definitive answer since I'm not an expert, but I don't see anything that changes InstanceIDs, and I see some infrastructure that saves them (I think). So it seems like you can use InstanceIDToObject and GetInstanceID.

Comment
Add comment · Show 5 · 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 yoyo · May 12, 2011 at 08:41 PM 0
Share

That appears to be the case. One thing to check would be to make sure that the instance ID of a particular game object or component is the same from one run of Unity to the next. The docs do say that the instance ID is unique. Note that instance ID's are 32-bit, while asset GUIDs are 128-bit, so obviously they aren't equivalent.

avatar image almo · Jun 02, 2011 at 07:24 PM 0
Share

I have more info on this now. It seems the InstanceIDs can change from load to load. Though they do not always do so. They do seem to remain static once the objects are loaded, though.

avatar image TowerOfBricks · Jun 09, 2011 at 05:20 PM 1
Share

Yes it seems so, I have experimented and found that they (at least some) change when changing scenes, so if you saved IDs in one scene, they only remain the same as long as you don't change to another scene and back again (usually).

avatar image TowerOfBricks · Jun 09, 2011 at 05:45 PM 0
Share

Unity seems to use an object called ReferenceData which contains an instanceID and a variable called "cachedPtr" (int) I'm not sure what it is for, perhaps a pointer to the memory address or something.

avatar image TowerOfBricks · Jun 09, 2011 at 06:20 PM 0
Share

Added a request on Unity Feedback: http://feedback.unity3d.com/forums/15792-unity/suggestions/1919441-serializable-unity-object-references

avatar image
0

Answer by sigs · Feb 03, 2012 at 04:45 AM

check out https://github.com/terravision/UnityTextScene

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 yoyo · Apr 24, 2012 at 04:36 PM 0
Share

This project seems redundant now that UT is using text-based yaml to serialize scenes and prefabs.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to prevent loading from freezing the game ? 2 Answers

Saving system tutorial / Load through main menu 1 Answer

AddObjectToAsset (reference) becomes null 1 Answer

Seperating editor and runtime data with ScriptableObjects 1 Answer

Save and load serialization problem 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