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 OctoMan · Jan 04, 2015 at 05:08 PM · guiinspectorcustom

Using different custom inspectorscripts

Hi,

i have 2 differnt inspector scripts. 1st is a property drawer to draw my own serialized class. 2nd is a custom editor.

When i use DrawDefaultInspector (); in the customeditor i get some errors in the console. But i need to do it to see the property drawer i made and all other bool vars including a label.

 NullReferenceException: Object reference not set to an instance of an object
 UnityEditor.EditorGUI.BeginProperty (Rect totalPosition, UnityEngine.GUIContent label, UnityEditor.SerializedProperty property) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:3856)
 UnityEditor.EditorGUI.DefaultPropertyField (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:4343)
 UnityEditor.PropertyHandler.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:144)
 UnityEditor.EditorGUI.PropertyFieldInternal (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:4338)
 UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/EditorGUIBindings.cs:711)
 UnityEditor.EditorGUI.PropertyField (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/EditorGUIBindings.cs:706)
 ColorSwitcherEditor.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/Color Switcher/Editor/ColorSwitcherEditor.cs:30)
 UnityEditor.PropertyDrawer.OnGUISafe (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23)
 UnityEditor.PropertyHandler.OnGUI (Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:134)
 UnityEditor.PropertyHandler.OnGUILayout (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:195)
 UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:5989)
 UnityEditor.EditorGUILayout.PropertyField (UnityEditor.SerializedProperty property, Boolean includeChildren, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:5983)
 UnityEditor.Editor.DoDrawDefaultInspector (UnityEditor.SerializedObject obj) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/Editor.cs:317)
 UnityEditor.Editor.DoDrawDefaultInspector () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/Editor.cs:327)
 UnityEditor.Editor.DrawDefaultInspector () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/EditorBindings.cs:232)
 ColorSwitcherEditor2.OnInspectorGUI () (at Assets/Color Switcher/Editor/ColorSwitcherEditor2.cs:23)
 UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1124)
 UnityEditor.DockArea:OnGUI()

and

 ArgumentException: Getting control 8's position in a group with only 8 controls when doing Repaint
 Aborting
 UnityEngine.GUILayoutGroup.GetNext () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayoutUtility.cs:513)
 UnityEngine.GUILayoutUtility.DoGetRect (Single minWidth, Single maxWidth, Single minHeight, Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayoutUtility.cs:306)
 UnityEngine.GUILayoutUtility.GetRect (Single minWidth, Single maxWidth, Single minHeight, Single maxHeight, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayoutUtility.cs:297)
 UnityEditor.EditorGUILayout.GetControlRect (Boolean hasLabel, Single height, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:6009)
 UnityEditor.EditorGUILayout.FloatField (System.String label, Single value, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:4929)
 ColorSwitcherEditor2.OnInspectorGUI () (at Assets/Color Switcher/Editor/ColorSwitcherEditor2.cs:26)
 UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1124)
 UnityEditor.DockArea:OnGUI()

In the Inspector all looks how it should but id like to know whats causing the errors and do i have to get rid of them when selling it on the asset store?

How do i mix them properly?

Comment
Add comment · Show 7
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 gjf · Jan 04, 2015 at 02:46 PM 0
Share

without seeing your code, it's hard to suggest anything.

"do i have to get rid of them when selling it on the asset store?" why would anyone pay money for something buggy? of course you need to fix it and provide good documentation and support.

avatar image OctoMan · Jan 04, 2015 at 03:54 PM 0
Share

ColorSwitcher Editor

 using System.Collections;
 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(switcher))]
 [CanEdit$$anonymous$$ultipleObjects]
 public class ColorSwitcherEditor : PropertyDrawer
 {
     public float setInterval;
     const int size = 50;
     public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
 
         EditorGUI.BeginProperty(position, label, property);
 
         SerializedProperty interval = property.FindPropertyRelative ("interval");
         SerializedProperty fadetoNext = property.FindPropertyRelative ("fadeToNext");
         SerializedProperty color = property.FindPropertyRelative ("color");
 
         EditorGUI.PrefixLabel(position, label);
 
 
         int indent = EditorGUI.indentLevel;
         EditorGUI.indentLevel = 0;
         EditorGUIUtility.labelWidth = 55f;
 
         EditorGUI.PropertyField (new Rect (position.width - 280, position.y, size*2, position.height),interval, new GUIContent("Interval"));
         EditorGUIUtility.labelWidth = 80f;
         EditorGUI.PropertyField (new Rect (position.width - 170, position.y, 100f, position.height),fadetoNext, new GUIContent("FadeToNext"));
         EditorGUI.PropertyField (new Rect (position.width - size, position.y, size, position.height),color, GUIContent.none);
         EditorGUI.indentLevel = indent;
 
         EditorGUI.EndProperty();
     }
 }

avatar image OctoMan · Jan 04, 2015 at 03:55 PM 0
Share

ColorSwitcherEditor2

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomEditor(typeof(ColorSwitcherV103))]
 [CanEdit$$anonymous$$ultipleObjects]
 public class ColorSwitcherEditor2 : Editor
 {
     public float setInterval = 0;
 
     public override void OnInspectorGUI()
     {
         ColorSwitcherV103 myScript = (ColorSwitcherV103)target;
         EditorGUILayout.HelpBox ("Color Switcher by Octo$$anonymous$$an", $$anonymous$$essageType.Info);
 /*        myScript.enable = EditorGUILayout.Toggle ("Enable", myScript.enable);
         myScript.reverse = EditorGUILayout.Toggle ("Reverse", myScript.reverse);
         myScript.pingPong = EditorGUILayout.Toggle ("PingPong", myScript.pingPong);
         myScript.useCurrentAsFirst = EditorGUILayout.Toggle ("Use Current as First", myScript.useCurrentAsFirst);
         myScript.beginWithElement = EditorGUILayout.IntField ("Begin with Element", myScript.beginWithElement);
 */
         DrawDefaultInspector ();
 
         setInterval = EditorGUILayout.FloatField ("set all Intervals to: ", setInterval);
         if (GUILayout.Button ("Set All Intervals")) 
         {
             for(int i = 0; i< myScript.switcherElements.Length; i++)
             {
             myScript.switcherElements[i].interval = setInterval;
             }
         }
     }
 }

avatar image OctoMan · Jan 04, 2015 at 04:14 PM 0
Share

The switcher class is inside ColorSwitcherV103

 using UnityEngine;
 using System;
 using System.Collections;
 
 [Serializable]
 public class switcher
 {
     public bool fadeToNext;
     public float interval;
     public Color32 color;
 }
avatar image OctoMan · Jan 06, 2015 at 01:03 AM 0
Share

Anyone have an idea how to fix that problem? Can i draw my serialized class in the same way a property drawer can with customeditor (screenshot)? That way i could avoid that problem and only use one editor script ins$$anonymous$$d of two.alt text

alt text

Thanks in advance.

gui_help01.png (4.6 kB)
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OctoMan · Jan 07, 2015 at 12:24 AM

Hi,

finally i found the solution.

The problem was the PropertyDrawer. So before drawing the propertyfields i need to check it.

 if(property.isArray)
         {
             EditorGUI.PropertyField (position, property, false);
         }
         else
         {
         
         EditorGUI.PropertyField (new Rect (position.width - 280, position.y, size*2, position.height),property.FindPropertyRelative ("interval"), new GUIContent("Interval"));
 }

Thats it. Cheers

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Custom GUI Elements in Inspector 0 Answers

Simple text in inspector components? 2 Answers

How do you get the default inspector to draw for Prefabs ? 2 Answers

Pressing "T" in the Sprite Editor trims the slice. It should only work when pressing "Shift+T". Please help 1 Answer

add gameobject via the inspector? 1 Answer


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