Do I need using System.Collections;?

I was following a Brackey’s tutorial, and he got rid of using ‘System.Collections;’ because it was useless. Is it really? What’s the purpose of it?

1 Like

It’s a namespace that contains various collection types:

If you’re not using any types in a namespace, you can safely delete it’s using declaration.
Visual Studio will indicate if you’re not using any types in a namespace by grey-ing out the using declaration.

System.Collections may have been useless for that specific tutorial, but it’s not useless altogether.

1 Like

The most likely reason you might want System.Collections is if you re using Unity coroutines. For actual collections people almost always use System.Collections.Generic instead.

3 Likes

Probably the primary reason why it’s added per default in Unity’s script templates is that it contains the IEnumerator interface, which is used when you implement coroutines - pretty common in Unity.

Like already mentioned, it also contains some other types, e.g. non-generic collection types, but they are not used as often since the better choice is generally a generic collection from System.Collections.Generic.