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 12, 2018 at 06:17 PM · editoreditor-scriptingserializationsaving

How do you save changes made with custom editor?

Hi, I'm writing custom editor something similar to what Sebastian Lague does in this series: Curve Editor . Video's TL; DR; You're adding some points in editor mode and draw bezier curve based on those points.

Now, what I want to do is to create similar editor, but than save result and show in game play mode as well. How would you go about saving this data? To sum it up I think it's enough to save points values from editor mode, and retrieve this values in game play mode, however I'm not sure how to do that.

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

3 Replies

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

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

I tried to skim through the video to see what the issue might be. I assume the author will show how to save the data later on, but he starts out placing his "path" class in the custom editor.

Simply move the "path" class to a new MonoBehaviour and add it as component to a GameObject in the scene. Then change the editor to a custom editor for that MonoBehaviour type to edit the data. If the path class and all of it's values are serializable, the data is saved.

Not sure, if part of the question, but showing the points as the video author does in the editor, is not as easy as showing them in the editor. The runtime does not have the UnityEditor.Handles classes and Gizmos are also only shown in the editor. There are other ways to show lines, e.g. via the LineRender, in the game, but that might be another question.

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 Longman1981 · Mar 14, 2018 at 06:25 AM 0
Share

Thanks for a detailed answer, I'm not sure how would your solution work, I'll test it when I get home. I found out that my problem could be solved by using scriptableobjects in that case we create asset and assign values to it. In your solution however it seems like every instance of path class will read serialized value of path variable? And does it mean that if I modify it in play mode, modifications will be saved as well?

avatar image
0

Answer by Longman1981 · Mar 14, 2018 at 09:33 AM

I think I got it now, and I'll explain what was problem for anyone else with same problem with understanding this issue.

Let's say you have custom TestScript, which doesn't inherit from anything at all. You set it serializable and have simple public int value. Now let's say in edit mode you create instance of this TestScript with "new" keyword, and set value to 10. Now let's say you enter play mode and you want to retrieve this value, so how would you find it? I thought I would create new instance of TestScript and if it's serializable than "value" would hold 10. However that's completely incorrect, Serializable means that object will be serialized, but you can't retrieve this serialized values only by knowing class, you need to find serialized object, you have no way to retrieve this "value" 10 in this case... Yes object of TestScript was serialized but you have no way of finding that serialized object. You have few other options: 1)Create ScriptableObject asset, than find this asset in Resources and retreive "value" 10 from it. 2)Attach your script to gameobject/prefab, than find with GetComponent/Instantiate prefab. In this case you will be able target certain object of TestScript type rather than TestScript itself. So to sum up you can't do this with custom script which doesn't inherit from unity's MonoBehavior/ScriptableObject

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

Answer by kauramanjeet0 · Mar 14, 2018 at 12:15 PM

Thanks a lot @Longman1981

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

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

Related Questions

Preview procedural texture in scene without serializing it? 1 Answer

OnSerialize event 2 Answers

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

SerializedProperty with children class fields 2 Answers

Is EditorUtility.SetDirty restricted to prefabs or inspected GameObject? 5 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