Resources.LoadAll + SelectionGrid : Ambiguous reference

Seems like this should work but does not. I get an "Ambiguous reference’SelectionGrid’ for “texButConWom”.

// Variables
private var intButConWomSel : int = 0;
private var texButConWom : Object[];

// GUI
function OnGUI ()
{
	// Load button pictures
	texButConWom = Resources.LoadAll("picConWomCleCon", Texture2D);

        // SelectionGrid
	intButConWomSel = GUI.SelectionGrid (Rect (0, 0, 320, 480), intButConWomSel, texButConWom, 5);
}

Any ideas on how to overcome this?

Thanks.

There exist 6 implementations of GUI.SelectionGrid, 2 of which match the 4 parameters in your call:

static function SelectionGrid (position : Rect, selected : int, images : Texture[], xCount : int) : int
static function SelectionGrid (position : Rect, selected : int, content : GUIContent[], xCount : int) : int

texButConWom is an array of type Object: both Texture and GUIContent inherit from Object, so the compiler doesn’t know which function call to choose. You need to explicitly define texButConWom as either a Texture[ ] or a GUIContent[ ], so the compiler knows which implementation of GUI.SelectionGrid to pick.

Thank you for your response tomvds.

I spent several hours researching this (documentation and forum) and attempting code without success. The documentation confirms what you wrote and my understanding is in line with this.

However:

“You need to explicitly define texButConWom as either a Texture[ ] or a GUIContent[ ], so the compiler knows which implementation of GUI.SelectionGrid to pick.”

This is where I am stuck. My numerous attempts to ‘explicitly define texButConWom’ have been unsuccessful and this is why I wrote to the forum.

Could you demonstrate this in a line of code?

Thanks again for your assistance.

Replace:

private var texButConWom : Object[];

by:
private var texButConWom : Texture[];.

If that for some reason isn’t working, you should explain more about what exactly you’re doing.

Ya. This seems like the obvious direction and I have tried this. Here is the new error message I get and the code:

InvalidCastException: Cannot cast from source type to destination type.

// Variables
private var intButConWomSel : int = 0;
private var texButConWom : Texture2D[];

// GUI
function OnGUI ()
{
   // Load button pictures
   texButConWom = Resources.LoadAll("picConWomCleCon", Texture2D);

        // SelectionGrid
   intButConWomSel = GUI.SelectionGrid (Rect (0, 0, 320, 480), intButConWomSel, texButConWom, 5);
}

I propose that someone try Resources.LoadAll with SelectionGrid and see if they can get this to work.

I would be happy to see any code where the two work together.

This function is VERY important to me because I need the ability to easily change large numbers of files just by dropping them into a folder. Doing this through the inspector is HIGHLY tedious and time consuming.

Thanks.[/i]