Sudden GUI.DrawTexture errors

Hi, this morning I suddenly got errors when trying to compile scripts. Everything was working the previous day.

I’m using Unity 5.2.4. So when I try to compile for instance something like this I get “Best overload method match for 'UnityEngine.GUI.DrawTexture(UnityEnginge.Rect, UnityEngine.Texture) ’ has some invalid arguments” and “Argument 2 cannot convert ‘Texture’ expression to type ‘UnityEngine.Texture’”. These errors appear at places like line10.

using UnityEngine;
using UnityEngine.Collections;

public class MainUI : MonoBehaviour
{
    public Texture sampleTex;

void OnGUI ()
{
   GUI.DrawTexture(new Rect(0, 0, 100, 100), sampleTex);
}
}

This happened to all of my scripts and got 344 of these errors in total. But why all of the sudden when it work yesterday. Any help will be greatly appreciated.

Thanks
–Andre

You have created or imported a custom class which is called “Texture” into the global namespace. That’s why your script is using the wrong “Texture” type.

You have basically two options:

  • Rename your custom “Texture” class or at least put it in a seperate namespace.
  • If you don’t want or if you aren’t able to do the first option you can also explicitly add the correct namespace to your Texture variable (and everywhere else where you use Unity’s Texture type)

So option 1 would be like this:

namespace MyCustomClasses
{
    // This is your custom Texture class
    public class Texture
    {
    }

}

Option 2 would be like this:

public class MainUI : MonoBehaviour
{
    public UnityEngine.Texture sampleTex;

If you are not sure where that custom Texture class is located, just right click on the “Texture” string in your MainUI class and select “go To declaration”. That menu point might be called different depending on which IDE you use. If you don’t use any IDE that supports this, try a search in all your project files for the string “class Texture”.