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
1
Question by Maximetinu · Mar 29, 2017 at 03:18 PM · inspectoreditor-scriptingconfig

Edit Static Class Config variables from editor

Hi all,

i'm using a static class with static public variables for some development configs. For example there I put the terrain layer name or the Debug flag, variables that will be accessed for many GameObjects.

I wonder how could I do to make a Custom Editor for the inspector in a way that I could modify this varaibles directly from the inspector.

Also, my mind is open to listen other advices about where to store this kind of variables.

Thanks, Metinu.

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
3
Best Answer

Answer by Bunny83 · Mar 29, 2017 at 04:15 PM

In short: you can't. Static classes as well as static variables aren't serialized. Therefore even when you create some editor GUI to edit those values, they won't be saved.

There are several ways to accomplish this:

  • Using an actual instance of a class and store the values as instances variables. You usually only have one instance of that class so the singleton pattern might be used to access those values from anywhere. You usually would use a ScriptableObject derived class which will be stored in the resources folder.

  • If those values are only relevant for the editor (so they are not used at runtime) you can use EditorPrefs instead. Note that the EditorPrefs are not stored inside the project folder, so they won't be transfered to another PC when you copy the project folder. Those are usually used for pure editor settings which have no relevance for the actual project.

  • Use your own serialization method. This could mean serializing the values as JSON or XML into a file which can be loaded at runtime / edit-time.

Which method is the best highly depends on the actual usage of those "values". If those settings are required at runtime i highly recommend the ScriptableObject / Singleton approach.

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 Maximetinu · Mar 30, 2017 at 12:57 PM 0
Share

Ok, unsterstood! Thanks a lot, I will learn how to get it with an Scriptable Object. Thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to get notification of moving a GameObject in the hierachy when editing the scene? 1 Answer

Creating a custom inspector utilizing a list of class instances with serialization? 1 Answer

Multiple scripts reference to the same SerializeField 1 Answer

Align text into PropertyField 1 Answer

GUILayout.BeginHorizontal sluggish in custom inspector 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