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
4
Question by Brian-Kehrer · Dec 19, 2010 at 03:31 AM · editor-scriptingcustom-inspectorcustom-editor

Custom Editors for classes that derive from system.object

Is there a way to override Unity's editor / inspector for standard classes deriving from System.Object? It appears to only work on classes deriving from MonoBehaviour.

For example, below, I'd like to hide or show 'exponent' based on the type selected in the editor. Obviously it would still serialize both values, but this is for editor display (and more complex cases).

[System.Serializable] public sealed class NormalizedCurve{

 public enum Type{Linear, Exponential}


 [SerializeField]
 Type type;

 [SerializeField]
 float exponent;

}

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
0

Answer by Dreamora · Dec 19, 2010 at 06:17 AM

I don't think so but you can derive from Object (technically UnityEngine.Object) which forms the base of all UnityEngine classes

Comment
Add comment · Show 2 · 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 Statement · Dec 19, 2010 at 06:43 AM 0
Share

Can you do that? For some reason I think I got errors when trying to inherit from anything $$anonymous$$onoBehavior inherits from (including UnityEngine.Object).

avatar image Brian-Kehrer · Dec 19, 2010 at 06:28 PM 0
Share

I suppose I could derive from ScriptableObject (since there are actually constructors for that). Still, I'd like to show the properties of this object in-line, without having to select the scriptableObject instance.

avatar image
0

Answer by Dreamora · Dec 27, 2010 at 05:29 AM

To answer Comment and concerns:

You only get problems by having stuff thats already "beyond" UnityEngine.Object normally (ie scriptableobject and its extends Component, Behaviour and MonoBehaviour) and even there only when you try to use New instead of AddXXX

As you marked it as serializable it will normally always show on the editor, just be aware of one major problem: As its serializable and not initialized by unity upon scene start (as scriptableobject, component and behaviours are) its treated similar to a struct, ie its always there basically, already in the editor even if not setup yet and out of my experience that then will lead to serious trouble (i've had totally undebuggable phantom issues due to a an own tree alike datastructure where the classes were serializable so I could see them in the editor)

I highly recommend to not mark it serializable if its directly exposed on the editor. Either make it serializable and write an EditorWindow that allows you to access it or make it serializable and mark its field on the monobehaviour in question with [HideInInspector]

If you need editor exposure, use ScriptableObject or SerializableObject instead (give SeriazableObject / SerializableProperty a look in the docs - its a bit scarse but you seem to be aware of the basics in relation to serialization :))

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

No one has followed this question yet.

Related Questions

Showing member ScriptableObject's in the Inspector 5 Answers

Custom editor tags not saving 1 Answer

How to force close Popup Window? 1 Answer

Persistently changing variables from custom editor 2 Answers

"User is Dragging the Transform Gizmo" in Editor 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