Version: Unity 6.2 (6000.2)
LanguageEnglish
  • C#

AddAndRemoveRequest

class in UnityEditor.PackageManager.Requests

/

Inherits from:PackageManager.Requests.Request_1

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

PropertyDescription
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.