Search Unity

Why does my inspector flicker when I type?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AcademyOfFetishes, Mar 22, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    This is very related to a previous unanswered question I asked here: https://forum.unity.com/threads/whe...he-scrollbar-jump-to-a-different-spot.648811/ You can find all the source code there. To summarize, I have a complex script called CharacterAccessories. It has a list of items. Each element is called a CharacterAccessory. Each CharacterAccessory has an Unlockable on it. So the relationship goes like this:

    CharacterAccessories -(hasMany)-> CharacterAccessory -(hasOne)-> Unlockable


    I have a custom drawer on Unlockable only. When the script gets so long that it needs a scrollbar in the inspector, typing causes the inspector to flicker. Here's a GIF showing that:



    When I remove the Drawer, this doesn't happen. Here's the code of the drawer:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. [CustomPropertyDrawer(typeof(Unlockable))]
    7. public class UnlockableDrawer : PropertyDrawer
    8. {
    9.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    10.     {
    11.         EditorGUI.BeginProperty(position, label, property);
    12.  
    13.         var indent = EditorGUI.indentLevel;
    14.         EditorGUI.indentLevel = 1;
    15.  
    16.         SerializedProperty successCountProperty = property.FindPropertyRelative("successCount");
    17.         SerializedProperty needDataProperty = property.FindPropertyRelative("needData");
    18.  
    19.         float xPosition = position.x;
    20.         var labelPosition = new Rect(xPosition, position.y, 80, EditorGUI.GetPropertyHeight(successCountProperty));
    21.         xPosition += 90;
    22.         var successCountRect = new Rect(xPosition, position.y, 140, EditorGUI.GetPropertyHeight(successCountProperty));
    23.         xPosition += 150;
    24.         var needDataRect = new Rect(xPosition, position.y, 230, EditorGUI.GetPropertyHeight(needDataProperty));
    25.  
    26.         var labelWidth = EditorGUIUtility.labelWidth;
    27.         EditorGUIUtility.labelWidth = 110;
    28.         EditorGUI.LabelField(labelPosition, new GUIContent("Unlockable"));
    29.         EditorGUI.PropertyField(successCountRect, successCountProperty, new GUIContent("Success Count:"));
    30.         EditorGUIUtility.labelWidth = 90;
    31.         EditorGUI.PropertyField(needDataRect, needDataProperty, new GUIContent("Need Data:"));
    32.         EditorGUIUtility.labelWidth = labelWidth;
    33.  
    34.         EditorGUI.indentLevel = indent;
    35.  
    36.         EditorGUI.EndProperty();
    37.     }
    38.  
    39. }
    As I said, you can find this code and all other code in my previous post. But why does the inspector flicker? Am I doing something wrong in my drawer?
     
  2. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    Found a solution. Check the linked post to see.