• 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
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 somet$$anonymous$$ng similar to what Sebastian Lague does in t$$anonymous$$s 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 t$$anonymous$$s data? To sum it up I t$$anonymous$$nk it's enough to save points values from editor mode, and retrieve t$$anonymous$$s values in game play mode, however I'm not sure how to do that.

Comment

People who like this

0 Show 0
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
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 $$anonymous$$s "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
Longman1981

People who like this

1 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

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

I t$$anonymous$$nk I got it now, and I'll explain what was problem for anyone else with same problem with understanding t$$anonymous$$s issue.

Let's say you have custom TestScript, w$$anonymous$$ch doesn't inherit from anyt$$anonymous$$ng at all. You set it serializable and have simple public int value. Now let's say in edit mode you create instance of t$$anonymous$$s TestScript with "new" keyword, and set value to 10. Now let's say you enter play mode and you want to retrieve t$$anonymous$$s 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 t$$anonymous$$s serialized values only by knowing class, you need to find serialized object, you have no way to retrieve t$$anonymous$$s "value" 10 in t$$anonymous$$s 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 t$$anonymous$$s asset in Resources and retreive "value" 10 from it. 2)Attach your script to gameobject/prefab, than find with GetComponent/Instantiate prefab. In t$$anonymous$$s case you will be able target certain object of TestScript type rather than TestScript itself. So to sum up you can't do t$$anonymous$$s with custom script w$$anonymous$$ch doesn't inherit from unity's MonoBehavior/ScriptableObject

Comment

People who like this

0 Show 0 · 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

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

Thanks a lot @Longman1981

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Custom inspector variable resets automatically 1 Answer

Serialize class that derives from abstract class 2 Answers

Trouble setting the object reference in a property drawer 0 Answers

Help with Missing Monobehaviours and Asset Serialization? 0 Answers

Storing data about an asset only in the editor 2 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