Change size of list?

How do I change the size of a list? I know doing a search just says it can’t be done however the questions are in relation to arrays not lists. And I’m pretty sure I’ve done this before but it is not a command that will automatically come up in monodevelop.

var myList:Transform[];

function Start() {

myList.length=3; //obviously doesn't work, read only.
transform.GetComponent("myScript").myList.size=3; //obviously no
}
myList.pop();

removes the last item in the list

myList.splice(0,1);

removes the first item in the list.

The code you show is using the built-in, native .NET array object. They are extremely fast but cannot be resized without rebuilding that array. Unity also provides access to normal Javascript-type arrays. They are less efficient than the first type, but are more versatile (can be resized, sorted, etc). You also have access to other standard .NET collection types (such as List) that are dynamically resized as you add and remove items.

See this page for more info.

Don’t ever use Javascript arrays; they are slow and untyped. Way too many people posting questions about “why does Unity have an error about casting to Object”. Just pretend they don’t exist, and use a generic List, which is faster and better.

–Eric