- Home /
Compiler suddenly started showing errors for seemingly no reason.
Some of my scripts have suddenly started showing compiler errors for no apparent reason.Essentially they all have a variation of this kind of thing:
using UnityEngine;
using System;
using System.Collections;
using UnityEngine.UI;
public class sampleScript : MonoBehaviour {
public Sprite m_Sprite;
public Image title_Image;
void Start (){
title_Image.sprite = m_Sprite;}
}
And are showing a compiler error like this: 'Image' does not contain a definition for 'sprite' and no accessible extension method 'sprite' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?)
It doesn't make any sense to me....It was working fine an hour ago, and I haven't done anything to these scripts in that time...
Any idea what is going on here?
Are you sure you haven't declared a class / struct Image
somewhere?
Try to right click on the Image
word and click on "Go to declaration" (F12 on Visual Studio Community)
Answer by Bunny83 · May 02, 2019 at 01:41 PM
Like Hellium said you have created (or imported) a type in the global namespace which is named "Image". You should either rename your own type or place it in your own namespace to avoid name collisions.