# PackageCollection

> A collection class that represents all packages in a Unity project, providing enumeration and error handling capabilities for package management operations.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.PackageManager](/engine/6000.5/script-reference/unityeditor/packagemanager.md)
* **Assembly:** UnityEditor.CoreModule
* **Implements:** [IEnumerable\<PackageInfo>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

```csharp
public class PackageCollection : IEnumerable<PackageInfo>, IEnumerable
```

## Remarks

Implements IEnumerable \<[PackageInfo](/engine/6000.5/script-reference/unityeditor/packagemanager/packageinfo.md)> interface.

The PackageCollection class serves as a container for [PackageInfo](/engine/6000.5/script-reference/unityeditor/packagemanager/packageinfo.md) objects representing all packages in a Unity project. PackageCollection information is typically obtained as the result of a [Client.List](/engine/6000.5/script-reference/unityeditor/packagemanager/client/list.md)() operation. Use the PackageCollection to iterate through packages and check for collection-level errors that might occur during package resolution.

```csharp
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;

public class PackageExample 
{
    void ListAllPackages()
    {
        ListRequest request = Client.List();

        while(!request.IsCompleted) {}

        if (request.Status == StatusCode.Success)
        {
            PackageCollection packages = request.Result;

            // Check for collection-level errors
            if (packages.error != null)
            {
                Debug.LogError($"Collection error: {packages.error}");
                return;
            }

            // Enumerate through packages
            foreach (PackageInfo package in packages)
            {
                Debug.Log($"Found package: {package.name} @ {package.version}");
            }
        }
    }
}
```

**Remarks**

* After the PackageCollection is created, it's immutable.
* Package enumeration order isn't guaranteed.
* Collection-level errors indicate issues with the overall package resolution, not with individual packages.
* The collection can contain direct dependencies and transitive dependencies.
* Use in conjunction with [Client.List](/engine/6000.5/script-reference/unityeditor/packagemanager/client/list.md)() to get an up-to-date view of project packages.

**Related information**

* [PackageInfo](/engine/6000.5/script-reference/unityeditor/packagemanager/packageinfo.md)
* [Client.List](/engine/6000.5/script-reference/unityeditor/packagemanager/client/list.md)
* [ListRequest](/engine/6000.5/script-reference/unityeditor/packagemanager/requests/listrequest.md)

## Properties

| Property                                                                                       | Description                                       |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| [error](/engine/6000.5/script-reference/unityeditor/packagemanager/packagecollection/error.md) | The error associated with the package collection. |
