- Home /
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
Answer by Bunny83 · May 29, 2016 at 01:37 PM
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".
ps: If you still can't find that class, it might be a UnityScript class. So just watch out for files that are named "Texture.js"
pps: If the custom Texture class is supposed to be a $$anonymous$$onoBehaviour, your best option is to rename it as a custom namespace won't work in that case. It's generaly advised to avoid names of any built-in classes / types.
Thanks man, it's these stupid mistakes that slips past you sometimes. Alternatively you can also just use Texture2D, but that's much more work replacing than just rena$$anonymous$$g a class.
Thanks again.
Your answer
![](https://koobas.hobune.stream/wayback/20220612081835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
GUI 2D Bounding Box 1 Answer
Erroe when resizing GUITextures in C# file 1 Answer
GUI Transparency Changing automatically 2 Answers
Doubt with GUILayout 0 Answers