Setting guiTexture.texture gives NullReferenceException

With the following code:

public Texture2D Tick;
public GUITexture Test;
void Start () {
	Tick = (Texture2D) GameObject.Find("Tick").guiTexture.texture;
	print(Tick);
	Test = new GUITexture();
	Test.texture = Tick;
}

I get the following output:

tick_mark (UnityEngine.Texture2D)

NullReferenceException
HUD.Start () (at Assets/Scripts/Player/HUD.cs:46)

Line 46 points to: “Test.texture = Tick;”

Obviously, as shown by the print statement, Tick definitely holds a valid Texture2D object.

Casting it explicitly using (Texture) or (Texture2D) has no effect, as does using Test.guiTexture.texture , or a combination of them.

I am very much stumped

A NullReferenceException gets thrown when you try to access a member on a null object. So my guess is that the problem is with Test, not with Tick. I believe that GuiTexture is a component not a game object, so doing what you are doing isn’t allowed. Here is a thread that I think will get you what you need:

http://forum.unity3d.com/threads/18321-GUITexture-from-script