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
0
Question by Longman1981 · Mar 13, 2018 at 09:02 AM · editoreditor-scriptingserializationdata storage

How do components(e.g transform) save data?

Let's say you place gameobject at the position (1;1). now as you're in editor mode, I guess one instance of transform object is created for this gameobject right? This transform object knows when you move gameobject and set's new position values. This all happens in editor mode, now when you move to game mode, We get new instance of this object, but this new one knows every change that happened in editor mode, so question is how do this two instances share data?

In other words, I would like to copy this behavior and create my own similar component, which will share data between editor and game mode.

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

1 Reply

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

Answer by Xarbrough · Mar 13, 2018 at 01:00 PM

Unity components do not share data between edit and play mode. They also don't know about changed made by the user.

Instead, Unity uses custom editors and handles to change component data. When a user selects a Transform, a handle appears in the scene and an inspector that component is shown. If you change the values via user input, the data gets written to the Transform components. Internally the data is handled by the Unity serializer, which we come in contact with via the SerializedObject and SerializedProperty classes. All data is actually marshalled to the C++ representation of objects in the engine. This is where the scene graph lives (a collection of all objects related to the current scene). The scene is stored as a binary or text file in the YAML format. If you select "Force Text Serialization" in the Editor settings, you can open a scene file to see how objects are saved to disk.

When you press play, the entire scene is destroyed an recreated. This is why we can't, for example, easily persist changes from play mode to edit mode afterwards. The exception being project assets, which maintain their values through play mode.

At play mode, the editor still provides the tools from edit mode, so you can still move object with the Transform handle and the values are being written to the component. However, these changes are not written to the YAML scene file to disk, therefore they are lost, when you exit play mode.

Coming back to your question. you said, that the Transform component at runtime knows the values from the Transform component at edit time. This is handled by the Unity serializer automatically. To make your own component you simply inherit from the MonoBehaviour class and add an instance of the component to a GameObject in a scene. Now, any serialized data is carried over to play mode.

Do you mean something else with your question? Generally you need to make sure that your data is serializable and as said, that scene objects are destroyed when entering and leaving play mode. Persisting changes from play mode back to edit mode might be relevant topic, but I'm unsure if you're asking about this.

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

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

111 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 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

Preview procedural texture in scene without serializing it? 1 Answer

OnSerialize event 2 Answers

How do you save changes made with custom editor? 3 Answers

SerializedProperty with children class fields 2 Answers

UnityEvent Serialization Problem 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