Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
8
Question by mift · Jun 07, 2010 at 08:54 AM · editorinspectorpropertyexpose

expose public property (not variable) in inspector

Hi there,

looking at most of Unitys builtin component through a reflection tool ( .net reflector, monodevelops builtin ), you can see that they dont have any public member variables.

I.e., the Rigidbody component has a property "isKinematic", but there is no public variable "bool m_isKinematic".

So, my question is, how do I expose a custom property to the inspector without writing a custom Component editor? Is this even possible?

Many thanks

[UPDATE] I tried by suggestion of a Unity IRC guy the EditorGUILayout.PropertyField() method, but it seems like that it doesnt expose properties ( the way they are meant in .NET, getters and setters ), instead SerializedObject exposes hidden variables which I believe arent meant to be public.

Still looking in a dark hole.

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

9 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by jonas-echterhoff · Jun 07, 2010 at 11:17 AM

As Mike said, you would need a custom inspector to do this - writing one should be really simple, though. Basically, you just use EditorGUILayout.TextField (or FloatField, or whatever fits your need) on your property, and then you call DrawDefaultInspector() to draw the normal inspector for all the other properties.

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
avatar image
5

Answer by mift · Jun 07, 2010 at 12:58 PM

Hi Jonas, following your answer I wrote a piece of code which does exactly what you meant.

Link to unifycommunity Unity wiki for those interested: Unify wiki entry

Comment
Add comment · Show 4 · 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 Matt 16 · Nov 19, 2010 at 11:59 AM 0
Share

Your wiki entry doesn't specify the location of the first class (the attribute), should this be in /Assets/Editor? Unity doesn't appear to be able to find the attribute class this way.

avatar image sam_bender · Sep 17, 2015 at 06:20 PM 0
Share

Archived version of the page because it no longer exists https://web.archive.org/web/20111206085547/http://www.unifycommunity.com/wiki/index.php?title=Expose_properties_in_inspector

avatar image Bunny83 sam_bender · Sep 17, 2015 at 09:07 PM 0
Share

@sam_bender
The page does still exist, however the unifycommunity wiki got integrated into the Unity website itself:

http://wiki.unity3d.com/index.php?title=Expose_properties_in_inspector

I fixed the link in the answer.

avatar image didii · May 05, 2016 at 12:37 AM 0
Share

Just so that everybody knows that comes by here. The first file (ExposePropertyAttribute.cs) does not belong in the editor folder, but rather in any other folder with another name. I'd change the wiki, but I need to request an account with my real name + biography.

avatar image
3

Answer by Stormwalker · Nov 14, 2013 at 03:24 AM

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnValidate.html

I just ran across this, and I'm kind of wondering if it's new - I certainly never noticed it before, nor in any of these discussion have I seen it mentioned. While this does not strictly speaking solve the problem of exposing properties in the inspector, it does minimize the need to.

My tests so far indicate that this does indeed only fire when editor settings are changed, and more specifically settings of the script in question.

While you can not respond to exactly what was changed, or how much it was changed - this still seems a better option than excessive use of custom inspectors, as both developing them (as an engineer,) and working with them (as an artist or designer) is cumbersome for the development pipeline. (See well known headaches with multi-object editing, and undo.)

On a side note - while this does stretch the definition of the intended purpose of this call - almost anything that responds to inspector changes, and makes appropriate adjustments is arguably validation.

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 Bunny83 · Nov 19, 2013 at 12:18 AM 0
Share

That's good to know ;) I always wanted more callbacks inside the editor. A lot stuff in the pipeline runs in the background without any chance of getting a notice about it.

I checked the release notes from 4.3 back to 3.4 and they didn't mentioned OnValidate anywhere, so they forgot to mention it ;)

However i think it might be quite new.

edit

Ok i just tried it in my Unity 4.0.1 version and it works, so it's there for quire a while, but i haven't seen it before in the docs. So maybe they just updated the docs ;)

avatar image
2

Answer by Tetrad · Jun 07, 2010 at 03:42 PM

Not exactly the answer you want, but it is possible to expose private members to the inspector window. Just use the [SerializeField] attribute.

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
avatar image
0

Answer by Mike 3 · Jun 07, 2010 at 09:48 AM

It's not possible without a custom inspector

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
  • 1
  • 2
  • ›

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Inspector Layer Mask variable 2 Answers

Property values changed by custom editor are reset when start playing 2 Answers

How to assign a field within a PropertyDrawer? 1 Answer

Unity inspector scripting - scriptable objects - card game 0 Answers

How to properly handle Undo events 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