DrawGUITexture: Texture is null

Hey guys, anyone knows how to fix this error? It’s a result of me opening my Dialogue Editor Window after a long time… :sweat_smile: :

DrawGUITexture: texture is null
UnityEngine.GUI:DrawTextureWithTexCoords (UnityEngine.Rect,UnityEngine.Texture,UnityEngine.Rect)
RPG.Dialogue.Editor.DialogueEditor:OnGUI () (at Assets/Project Backup/Scripts/Dialogue/Editor/DialogueEditor.cs:120)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

and this is the ‘DialogueEditor.OnGUI()’ function the error is leading me to (and I commented line 120 beside the respective line):

     private void OnGUI() {

         if (selectedDialogue == null) {
        
        EditorGUILayout.LabelField("No Dialogue Selected.");
        
         }

         else {

            ProcessEvents();

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); // ends with 'EditorGUILayout.EndScrollView()' below
            
            Rect canvas = GUILayoutUtility.GetRect(canvasSize, canvasSize);  // creates virtual space so we can horizontally scroll our Dialogue Editor (to make it bigger, increment this number)

            Texture2D backgroundTex = Resources.Load("background") as Texture2D;
            Rect texCoords = new Rect(0, 0, canvasSize/backgroundSize, canvasSize/backgroundSize);

            GUI.DrawTextureWithTexCoords(canvas, backgroundTex, texCoords); // line 120

                foreach (DialogueNode node in selectedDialogue.GetAllNodes())
                {
                    DrawConnections(node);
                }

                foreach (DialogueNode node in selectedDialogue.GetAllNodes()) {

                    DrawNode(node);

                }

                EditorGUILayout.EndScrollView();

                if (creatingNode != null) {

                  
                  selectedDialogue.CreateNode(creatingNode);
                  creatingNode = null;      // stops creating more than one node

                }

                if (deletingNode != null) {

                  selectedDialogue.DeleteNode(deletingNode);
                  deletingNode = null;

                }

            }

        }

(if Brian sees this, please respond to this after the tutorial ;P)

This is a quickie, as it’s invariably the same thing:

  • Make sure that the background texture is in a folder named Resources. As we are loading by name, it must be at the root of a Resources folder, not in say Resources/Textures
  • Make sure that the Texture’s import dialogue lists the texture as a Texture and not a Sprite.

OK so… all I did was rename the background_02.png Texture2D I had to ‘background’, and placed it in a resources folder. That did not get the grid to show up as I wanted, but it’s not complaining, and that’s good enough for me for now :slight_smile:

Thanks Brian

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms