Any way to force one class to be my 'default' class of that name?

I know the title is a bit confusing, I just couldn’t think of a concise way of asking what I’m actually asking.

I’m using the Vuforia AR plugin, and making extensive use of 4.6’s new UI. Both of these have a class named ‘Image’. Fortunately, the UI’s class is inside the UnityEngine.UI namespace, so it still compiles and everything.

The problem is that when scripting, even if I have “using UnityEngine.UI” in the script, the compiler still thinks that “Image” refers to the Vuforia class. I don’t seem to be able to shake this, and the only way around it is to use UnityEngine.UI.Image every.single.time I want to use that class. It’s infuriating.

Is there a way to make the compiler realize that, no, I never actually want to use Vuforia’s class?

I haven’t tried it, but what if you tried moving the include to before/after the conflicting class? Just switch whichever way it currently is.

Off the top of my head, I know of no such thing, but what you CAN do is use C#'s type-aliasing:

using UnityImage = UnityEngine.UI.Image;

void Start()
{
  var image = GetComponent<UnityImage>();
}
1 Like

Well, that does make it moderately less annoying, thanks.