AddAndRemoveRequest
Represents an asynchronous request to add package dependencies to the project, remove package dependencies from the project, or both.
Read time 1 minuteLast updated 11 days ago
Definition
- Type: Class
- Namespace: UnityEditor.PackageManager.Requests
- Assembly: UnityEditor.CoreModule
- Inherits from: Request<PackageCollection>
- Implements: ISerializationCallbackReceiver
public sealed class AddAndRemoveRequest : Request<PackageCollection>, ISerializationCallbackReceiver
Remarks
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.
Dry run support: When you call the Client.AddAndRemove method with set to , the Package Manager simulates the add and remove operations without actually changing the project. The Result property contains the simulated final package state, which allows you to preview your changes as if was .
dryRuntruedryRunfalseusing 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; } }}
Related information