- Home /
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?
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.
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();
}
}
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;
}
}
}
}
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;
}
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
Thanks in advance.
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
Your answer
Follow this Question
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
add gameobject via the inspector? 1 Answer