AddAndRemoveRequest

class in UnityEditor.PackageManager.Requests

/

Inherits from:PackageManager.Requests.Request_1

Switch to Manual

Description

Represents an asynchronous request to add package dependencies to the project, remove package dependencies from the project, or both.

The PackageManager Client class returns an AddAndRemoveRequest instance when you call the Client.AddAndRemove method to add or remove package dependencies in the project. Use this object to determine when the request is complete and to access the result.

After the request completes, you can retrieve the PackageCollection instance from the Result property.

using UnityEngine;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
[ExecuteInEditMode]
public class PackageManagerAddRemoveExample : MonoBehaviour
{
    AddAndRemoveRequest m_Request;
    
    void Start()
    {
        Debug.Log("Client.AddAndRemove example...");
        
        var packagesToAdd = new[] 
        { 
            "com.unity.textmeshpro",
            "com.unity.inputsystem"
        };
        
        var packagesToRemove = new[] 
        { 
            "com.unity.timeline" 
        };
        
        m_Request = Client.AddAndRemove(packagesToAdd, packagesToRemove);
    }

void Update() { if (m_Request != null && m_Request.IsCompleted) { if (m_Request.Status == StatusCode.Success) { Debug.Log("Packages updated successfully:"); } else { Debug.LogError($"Operation failed: {m_Request.Error.message}"); } m_Request = null; } } }

Inherited Members

Properties

ErrorThe error returned by the request, if any.
IsCompletedWhether the request is complete.
StatusThe request status.
ResultA property that provides access to the result of a completed Package Manager request operation.

Did you find this page useful? Please give it a rating: