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
0
Question by kingdavid127 · Jun 03, 2014 at 05:38 PM · editorscenevariables

How can I save scripted variable changes?

Right now, I have some monobehaviours attached to gameObjects within my scene. There are public variables in these monobehaviours that I can change in the inspector.

If I change the values manually, they become bold in the inspector and save when I save the scene.

If I change the values via another script, they don't become bold in the inspector and don't save when I save the scene but instead reset to the default values of the script.

I would like to have Unity save values that have been changed via a script. Is there a way to enable this?

EDIT: I should clarify that the scripts I'm using are Editor scripts that I run from the Window dropdown. The variable changes are made without entering playmode.

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 Jeff-Kesselman · Jun 03, 2014 at 05:40 PM

Short answer is no. All changes that occur during gameplay are reset at the end of the gameplay.

This is behavior you absolutely need for development purposes.

Longer answer, you can write scripts that are executed during editing rather then just during gameplay.

To do that you use the http://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html attribute.

You can also write custom editor code to build new functions into the inspector and editor.

See http://docs.unity3d.com/Manual/ExtendingTheEditor.html

Comment
Add comment · Show 3 · 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 kingdavid127 · Jun 03, 2014 at 05:43 PM 0
Share

I think the ExecuteInEdit$$anonymous$$ode may be exactly what I needed. I'll give it a try and post back. Thanks!

EDIT: I added [ExecuteInEdit$$anonymous$$ode] to the top of my editor scripts above the class declaration but the values still don't stick when I save the scene, close it, and reopen it. Am I doing it wrong?

avatar image Jeff-Kesselman · Jun 03, 2014 at 06:08 PM 0
Share

You may have to tell it its been changed

See http://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html

avatar image kingdavid127 · Jun 03, 2014 at 06:55 PM 0
Share

That did it! After I changed the value, I used SetDirty on it and it saves with the scene now. I took out ExecuteInEdit$$anonymous$$ode because it worked without it(I think because I was using Editor scripts).

Thanks! That's a huge help.

avatar image
0

Answer by loz999 · Jun 03, 2014 at 06:10 PM

Be careful when using executeInEditMode as you can change all sorts of stuff that you don't want to that won't revert when you exit. Are you wanting something similar to ApplicationSettings in visual studio to save progress, level, XP, gear etc. or is there another reason?

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 kingdavid127 · Jun 03, 2014 at 06:57 PM 0
Share

I was using it to quickly edit items that would later be spawned in game. I ended up removing the ExecuteInEdit$$anonymous$$ode and just used SetDirty ins$$anonymous$$d.

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

23 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

Related Questions

Assign Color[] var in prefabs using Editor Scripting 1 Answer

Custom Transform Editor in Scene Editor 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to change variables from a script in another scene? 1 Answer

EventSystem micro lag on the first touch 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