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 zloidooraque · Apr 13, 2015 at 01:10 PM · inspectorinheritancemonobehaviour

have i derive from MonoBehaviour to expose fields in inspector?

hi, i wasn't able to find an answer in docs after quick search, so may be someone will tell me. is it mandatory for class to be derived from MonoBehaviour to have its fields exposed?

Comment
Add comment · Show 5
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 AlwaysSunny · Apr 13, 2015 at 04:30 AM 0
Share

If you add the [System.Serializable] attribute to any class whose members can be serialized, you can expose fields or collections of such objects in the inspector. But those fields or collections must belong to a monobehavior-derived object to be visualized in the inspector.

The alternative involves an editor script which somehow bypasses this requirement; in effect, it IS possible to edit non-monobheavior-derived objects in the inspector, but you will be coding every aspect of this custom inspector behavior yourself.

In five years, I've only done this once. I decided it was more trouble than living with the inconveniences associated with exposing serializable objects via an otherwise-useless monobehaviour derivative.

avatar image zloidooraque · Apr 13, 2015 at 06:59 AM 0
Share

thanks. since the representation of classes i wanna to expose will be heavily custom itself, i will be writing custom editor scripts for it anyway

just for information: you say 'fields or collections must belong to monobehavior-derived object', but if just some object (non-monobehaviour-derived), that contains those fields and collections belongs to monobehavior-derived object it will not work, as i guess?

avatar image AlwaysSunny · Apr 13, 2015 at 01:27 PM 0
Share

You kind of lost me there. Hard to word these things sometimes. The gist is, without a custom inspector and methodology for handling everything, exposing anything requires at least one monobehavior.

Where else could you observe it? But you can "drill down" as far as you like, I think... Been a while since it's come up; I stuck with practices that circumnavigate these situations.

 // you can edit aFloat and anInt from this object
 public class Holder : $$anonymous$$onoBehavior {
   public SomeReferenceType someRefType;
 }
 
 [System.Serializable]
 public class SomeReferenceType {
   public float aFloat;  // this field will be visible
   public AnotherReferenceType anotherRefType;
 }
 
 [System.Serializable]
 public class AnotherReferenceType {
   public int anInt;  // this field will be visible
 }
avatar image _dns_ · Apr 13, 2015 at 02:04 PM 0
Share

Hi, you can also derive from ScriptableObject if the data you want to edit/store/read does not need to be attached to a gameobject. You can also have custom inspector etc...

avatar image zloidooraque · Apr 13, 2015 at 02:35 PM 0
Share

thanks guys for you patience. i'd be like 'just f**king try it', if i were you

and i will try it, of course

0 Replies

· Add your reply
  • Sort: 

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 add InfoBox to my class? 0 Answers

Can i extend or customise editor for all MonoBehaviours? 3 Answers

MonoBehaviour Inheritance, Singletons and Generics 1 Answer

Change a Class in the inspector 1 Answer

What is the most elegant solution to replace multiple inheritance for this? 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