Dynamic GUI Content Array

I am using Resources.Load to pull a texture image from the project and then taking values from that and creating a new GUIContent variable from them. But when I try to push or add them into a GUIContent[ ] it tells me that Add nor Push are part of (UnityEngine.GUIContent); I can add them into an array just fine but I can’t then feed the array into a Selection Grid since it is not a GUIContent[ ];

Any advice on how to do this?

function GUIContentFill(vendorCatalog : String, vendorID : int){
	var vendorList = new Array();
	var vendorInventory = new Array();
	
	vendorList = vendorCatalog.Split(char.Parse("#"));
	for(var i = 0; i < vendorList.length; i++){
		vendorInventory = vendorList[i].Split(char.Parse("|"));
		var endPos = (vendorInventory[0].Length - stringStartPos);
		var itemName : String = vendorInventory[i].Substring(stringStartPos, endPos);
		var itemTex : Texture2D;
		itemTex = Resources.Load("EndlessVoidCatalog/" + vendorInventory[0]);
		var itemTool : String = itemName;
		
		var newGUIContent : GUIContent = new GUIContent(itemName, itemTex, itemTool);
		storeInventory.Add(newGUIContent);   //Array()
//		storeGUIContents.Add(newGUIContent); //GUIContent[]
	}
}

I’m wanting to use a SelectionGrid because you can only buy one thing at a time through a “Buy Now” button. I’m open to other ideas however.

I understand that the native .NET arrays are static in code and have to be changed through the inspector, I was just wondering if anyone had figured out a work around for this for use in functions that require a .NET array like GUI.SelectionGrid.

Native built-in arrays can most certainly be changed at run-time with code, it’s just that you cannot change their length in particular. But apart from that they can be created, items in them replaced with new data (of the same type), etc., none of this requires you to use the Inspector. If you need to add/remove items to/from a built-in array then do as the Array documentation shows you, convert it to a standard array, add/remove as needed, convert it back to a built-in array. Done! :slight_smile:

Yeah, I’m actually aware that you can change out the content inside of the array. it was more about the length of the native array since I don’t have control of how many things need to be displayed.

Thanks HiggyB.

I’ll make sure to try and clarify my question more appropriately next time. :slight_smile: