Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

EditorGUILayout.GradientField not working properly

Discussion in 'Editor & General Support' started by Vinark117, Mar 29, 2020.

  1. Vinark117

    Vinark117

    Joined:
    Dec 10, 2019
    Posts:
    1
    I have a little problem with the gradient field in my custom editor window.
    The problem is that when I import the script to a project (or I change something in the script) the gradientfields in the editor window just randomly decides that they don't want to work. When I delete the fields from the code and then I readd the exact code it is working again. Is this a bug or what? I'm really frustrated by that, I'm creating an asset, but it's useless if it breaks after importing.

    Should show this:
    upload_2020-3-29_16-23-29.png
    but shows this:
    upload_2020-3-29_16-22-33.png

    This is the error I get:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.GradientEditor.GetMaxColorComponent (UnityEngine.Gradient gradient) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.GradientEditor.DrawGradientSwatchInternal (UnityEngine.Rect position, UnityEngine.Gradient gradient, UnityEditor.SerializedProperty property, UnityEngine.Color bgColor) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.GradientEditor.DrawGradientSwatch (UnityEngine.Rect position, UnityEngine.Gradient gradient, UnityEngine.Color bgColor) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.EditorGUI.DoGradientField (UnityEngine.Rect position, System.Int32 id, UnityEngine.Gradient value, UnityEditor.SerializedProperty property, System.Boolean hdr) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.EditorGUI.GradientField (UnityEngine.Rect position, UnityEngine.GUIContent label, UnityEngine.Gradient gradient, System.Boolean hdr) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.EditorGUI.GradientField (UnityEngine.Rect position, UnityEngine.GUIContent label, UnityEngine.Gradient gradient) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.EditorGUI.GradientField (UnityEngine.Rect position, System.String label, UnityEngine.Gradient gradient) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    UnityEditor.EditorGUILayout.GradientField (System.String label, UnityEngine.Gradient value, UnityEngine.GUILayoutOption[] options) (at <3e481e8f36eb4d4c8d94b9ba6b2be438>:0)
    MeshGeneratorWindow.ShowGradientfieldCustomvoidbecauseiDontKnowWhatTodothisshitisbroken (System.String _label, UnityEngine.Gradient _gradient) (at Assets/Mesh Generator Tools/Scripts/MeshGeneratorWindow.cs:290)
    MeshGeneratorWindow.OnGUI () (at Assets/Mesh Generator Tools/Scripts/MeshGeneratorWindow.cs:251)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    UnityEngine.UIElements.UIR.RenderChain.Render (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection, UnityEngine.UIElements.PanelClearFlags clearFlags) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.UIRRepaintUpdater.DrawChain (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.Panel.UpdateForRepaint () (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <b74e373726c44093a12f440dfb8c99b8>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <817eebdd70f8402280b9cb11fff8b976>:0)
     
    chadfranklin47 likes this.
  2. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    217
    I'm getting this same issue in Unity 2021.3.11 LTS