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
0
Question by StewVanB · Oct 11, 2017 at 02:44 PM · editorserializationeditorwindowextensionserializedobject

PropertyDrawer and EditorWindow

I am creating an editor script for our designers to use to configure some complex behavior. I am using a package that adds a node editor window to the unity UI. I am running into an issue with the CustomPropertyDrawers that I have created. The drawers work in the Inspector panel, but not in the EditorWindow class.

Does override for OnGUI in property draw get executed in a different place than the regular OnGUI that is used for EditorWindow?

The package is available here: https://github.com/Seneral/Node_Editor_Framework

Here is the object test code:

 using System.Collections;
 using System.Collections.Generic;
 using System.Runtime.Serialization;
 using UnityEngine;
 using UnityEditor;
 
 [System.Serializable]
 public class SomeBaseObject {
 
     [SerializeField]
     private int someBaseProperty;
 
     public SomeBaseObject(){
 
     }
 
     public SomeBaseObject(int _value){
         someBaseProperty = _value;
     }
 }
 
 [System.Serializable]
 public class SomeChildObject : SomeBaseObject {
 
     [SerializeField]
     private bool someChildProperty;
 
     public SomeChildObject(){
         
     }
 
     public SomeChildObject(bool _value){
         someChildProperty = _value;
     }
 }
 
 [CustomPropertyDrawer(typeof(SomeBaseObject))]
 public class SomeBaseObjectDrawer : PropertyDrawer {
 
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label){
         // Using BeginProperty / EndProperty on the parent property means that
         // prefab override logic works on the entire property.
         EditorGUI.BeginProperty(position, label, property);
 
         // Draw label
         position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
 
         // Calculate rects
         Rect someBaseRect = new Rect(position.x, position.y, 30, position.height);
         EditorGUI.PropertyField(someBaseRect, property.FindPropertyRelative("someBaseProperty"), GUIContent.none);
 
         EditorGUI.EndProperty();
     }
 
 }
 
 [CustomPropertyDrawer(typeof(SomeChildObject))]
 public class SomeChildObjectDrawer : SomeBaseObjectDrawer {
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label){
         base.OnGUI (position, property, label);
 
         // Using BeginProperty / EndProperty on the parent property means that
         // prefab override logic works on the entire property.
         EditorGUI.BeginProperty(position, label, property);
 
         // Draw label
         position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
 
         // Calculate rects
         Rect someChildRect = new Rect(position.x + 30, position.y, 30, position.height);
         EditorGUI.PropertyField(someChildRect, property.FindPropertyRelative("someChildProperty"), GUIContent.none);
 
         EditorGUI.EndProperty();
     }
 }

The first two images show that it works in the Inspector area of the Editor. The 3rd image shows the CustomEditorWindow. As you can see the Node is blank, but should be running the same OnGUI code the inspector does. https://imgur.com/a/4SY3z

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
0

Answer by StunAustralia · Aug 23, 2018 at 06:45 AM

@wolftamer389 hey! Did you ever get this resolved? I have a similar issue I've reproduced with the PropertyDrawer example on the Unity site.

Basically, if I try and edit the thing from a custom editor on a mono behaviour, like so:

 [CustomEditor(typeof(RecipeWithEditor))]
 public class RecipeWithEditorEditor : Editor
 {
    public override void OnInspectorGUI()
    {
       serializedObject.Update();
       SerializedProperty myIngredientProp = serializedObject.FindProperty("ingredient");
 
       EditorGUILayout.PropertyField(myIngredientProp, new GUIContent("Ingredient"));
 
       serializedObject.ApplyModifiedProperties();
    }
 
 }

I get this: alt text Which is correct.

However, when I do it from an EditorWindow with:

 private void OnGUI()
    {
       SerializedObject serialisedObject = new SerializedObject(this);
       SerializedProperty myIngredientProp = serialisedObject.FindProperty("myIngredient");
 
       EditorGUILayout.PropertyField(myIngredientProp, true);
 
       serialisedObject.ApplyModifiedProperties();
    }


I get this: alt text Which is not correct.

It's driven me nuts for hours now!

Anyone! What am I missing?

Cheers :)


monobehaviour-editorinspector.png (10.4 kB)
editorwindow.png (8.3 kB)
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 StewVanB · Aug 23, 2018 at 05:33 PM 0
Share

$$anonymous$$an this post is old... I'll have to check my code on that to see if it was ever resolved. It got handed off to another developer that has more experience with editor scripts.

Is the issue that you are having that the parts are out of order and not displayed as a row?

avatar image StunAustralia StewVanB · Aug 28, 2018 at 04:16 AM 0
Share

Sorry for the late reply - the issue is that it's not displayed as a row, ie the PropertyDrawer is ignored. $$anonymous$$y actual object is a fair amount more complex than this example, but this it it boiled down :)

avatar image StewVanB StunAustralia · Aug 28, 2018 at 02:46 PM 1
Share

This seems to be a solution to the issue you are having. I will have to try it out on my own when I can make the time. https://forum.unity.com/threads/how-to-use-make-editorwindow-use-custompropertydrawer.484020/

Show more comments

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

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

Related Questions

Creating persistent object in Edit mode 1 Answer

SerializedObject IntValue Multi Editing only applies to first object. 0 Answers

GUI Editior Script not working in ( Unity 2019.x ) 0 Answers

OnSerialize event 2 Answers

ApplyModifiedProperties() for UnityEvent ignores method name 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