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
5
Question by MihaiAilioai · Apr 10, 2013 at 08:22 PM · editorpropertydrawercustom inspector

Mixing custom editors with custom property drawers, possible ?

Is it possible to display custom property drawers inside custom editors ? I've been struggling to achieve this result without much luck.

Here's an oversimplification of my problem:

 [Serializable]
 public class A
 {
     public int intValue;
 }
 
 [Serializable]
 public class B
 {
     public A instanceOfA;
 }

I have a custom editor for class B and a custom drawer for class A and i want to use the custom drawer instead of reimplementing the functionality inside the custom editor.

The custom drawer displays fine inside a class that doesn't have a custom editor (uses the default inspector), but i can't seem to be able to "call" it inside my custom editor.

From what i've read, custom drawers are called if i use the EditorGUILayout.PropertyField method, but the problem with that is it expects a SerializableProperty and i can't get a hold of one of those since my classes don't extend Object.

Any help with this would be greatly appreciated, even if it means letting me know that this isn't yet possible.

Thank you !

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

Answer by Bunny83 · Apr 10, 2013 at 08:44 PM

I never tried it, but i guess it should be possible. Have you tried using a PropertyField in your custom editor? I think that should actually draw the property with a proper PropertyDrawer.

edit
Well a PropertyField of course needs a SerializedProperty to work with. This can be aquired from a SerializedObject.

Inside a custom editor you already get such an object in the serializedObject variable. Note: If your editor allows multiedit this SerializedObject represents all selected objects at once!

You can also create your own SerializedObject like this:

     SerializedObject obj = new SerializedObject(objectToInspect);
     // And as well by passing an array of objects:
     SerializedObject obj = new SerializedObject(arrayOfObjectsToInspect);

isEditingMultipleObjects can be used to determine if multiple objects are edited. Also important, if you want to support multiediting, is hasMultipleDifferentValues.

Comment
Add comment · Show 5 · 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 MihaiAilioai · Apr 11, 2013 at 06:34 AM 1
Share

Solved !

@Bunny83 I wanted to use that but like i mentioned in my post, i noticed it required a SerializableProperty and i had no idea how to get one of those from the objects i was working with.

That's until i realized that my custom editor, besides having a target object that i was casting to class B and obtaining/displaying properties for, also had a serializedObject member generated from the current $$anonymous$$onoBehaviour that is being edited.

From that i was able to obtain the property i needed via the FindProperty method of the serializedObject.

I basically did serializedObject.FindProperty("instanceOfA") and i got a hold of the serialized property used for instanceOfA, and i could then pass that to PropertyField which correctly displayed my custom drawer.

avatar image Chronos-L · Apr 11, 2013 at 06:53 AM 0
Share

@mihaiailioai, if @bunny83 answer's is correct, then you should mark it so. Upvote to the question and answer because I was wondering about that too when I start using c# nested class.

avatar image Bunny83 · Apr 11, 2013 at 03:43 PM 0
Share

@$$anonymous$$ihaiAilioai: Yes, sorry, i just thought that you know how the SerializedObject / Property works since you talked about the property drawer and custom editor like you used it already a few times ;) I added some basic information on how to use the SerializedObject

avatar image greggman · Aug 05, 2015 at 04:21 PM 0
Share

I know this Question is old but PropertyDrawers are not working in my custom editor. I made a [Serializable] public class Foo { [TextArea(10,10)] public string text; } . If use Foo in a $$anonymous$$onoBehavior I get the correct large text area. But if I use Foo in a custom EditorWindow and draw the SerializedObject in OnGUI with EditGUILayout.PropertyField(serializedProperty, true), the fields I defined in Foo show up but all the attributes about how to display them are ignored. Any idea how to fix that?

avatar image Stephen_O · Sep 10, 2015 at 10:28 PM 0
Share

Works flawlessly! Thanks for explaining this..

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

13 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

Related Questions

Disabling a button in custom editor script leaves ghost buttons 0 Answers

Caching data for a PropertyDrawer 1 Answer

Why PropertyDrawers shared same values? 2 Answers

How to show type text in EditorGUI.ObjectField? 1 Answer

PropertyDrawer not updating 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