GameObject[] type array size?

ok in normal c# you could just say GameObject g = new GameObject[3];
then some where in code say g.length or something of the sort but i cannot find anything of that sort to return the amount of elements or the size of my type array… what am i doing wrong.

g.length is it.

Maybe Length, but I am pretty sure length.

I have tried that, this is what i get.

Assets/Scripts/Weapon/TestPlaceHolder/WeaponCustomization.cs(24,32): error CS1061: Type UnityEngine.GameObject[ ]' does not contain a definition for length’ and no extension method length' of type UnityEngine.GameObject’ could be found (are you missing a using directive or an assembly reference?)

No, all properties in .NET are uppercase. Unity uses “normal C#” so there’s nothing special or different.

–Eric

1 Like

Thanks everything is working fine now.

Can someone help me
I got exactly this error message:
UnityEngine.Gameobject[ ] does not contain a definition for ‘‘Length’’

Is it still null?

If you got exactly that message then you named it Gameobject rather than GameObject.

I was having the same issue. What worked for me was using

private GameObject[ ] list;

and then

list.Length;

to get the length of the list. Note the capital L.

hi I am facing same issue can anyone help please?

3445461--272805--error.PNG

capital ‘L’ as posted, for ‘.Length’. Also , make sure that you match opening and closing braces ‘{’ and ‘}’.

:slight_smile:

error CS0200: Property or indexer ‘Array.Length’ cannot be assigned to – it is read only

You can’t change the size of an array by assigning a new value to Length. Either create a new array of the desired size or use a List instead.

1 Like

Lenght = Length