Search Unity

Question Null texture passed to GUI.Draw Texture.

Discussion in 'Editor & General Support' started by jonahthebear, Sep 19, 2021.

  1. jonahthebear

    jonahthebear

    Joined:
    Mar 7, 2021
    Posts:
    2
    I am trying to embed a texture into a custom editor window, when running the script it produces the following error:
    ignore the unity forum emojis lol.

    The texture is just a normal texture, works when using it on a canvas image etc.

    the texture is located in the Editor Default Resources folder, that's why I've tried using the EditorGUIUtility.Load function.

    Is there something I am missing?

    Code (CSharp):
    1. public class WindPainter : EditorWindow
    2. {
    3.     // tried setting the texture manually by picking it.
    4.     // public Texture ColorWheel;
    5.     Color color;
    6.     public float BrushSize = 100;
    7.     public float WindDirection = 1;
    8.     public float Intensity = 50;
    9.  
    10.     [MenuItem("Tools/Wind Painter")]
    11.     public static void ShowWindow()
    12.     {
    13.         GetWindow(typeof(WindPainter));
    14.     }
    15.  
    16.     private void OnGUI()
    17.     {
    18.         GUILayout.Label("Wind Brush", EditorStyles.boldLabel);
    19.         //tried obtaining it this way as well.
    20.         Texture ColorWheel = (Texture)EditorGUIUtility.Load("ColorWheel");
    21.  
    22.         GUI.DrawTexture(new Rect(10, 10, 200, 200), ColorWheel, ScaleMode.ScaleToFit, true, 10.0F);
    23.  
    24.         EditorGUILayout.Space();
    25.         EditorGUILayout.Space();
    26.         EditorGUILayout.Space();
    27.         EditorGUILayout.Space();
    28.  
    29.         WindDirection = EditorGUILayout.Slider("Wind Direction", WindDirection, 1f, 360f);
    30.  
    31.         Intensity = EditorGUILayout.Slider("Intensity", Intensity, 0, 100);
    32.  
    33.         BrushSize = EditorGUILayout.Slider("Brush Size", BrushSize, 50f, 500f);
    34.     }
    35. }
    Edit: I did a debug check to see if either of the methods were even loading the texture at all and it came back false for both, even though I can see the texture in the inspector.
     
    Last edited: Sep 19, 2021