AddRequest

class in UnityEditor.PackageManager.Requests

/

Inherits from:PackageManager.Requests.Request_1

Switch to Manual

Description

Represents an asynchronous request to add a package to the project.

The PackageManager Client class returns an AddRequest instance when you call the Client.Add method to add a package to your project. Use this object to determine when the request is complete and to access the result.

Once the request comsplete, you can retrieve the PackageInfo instance from the Result property.

using UnityEngine;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
[ExecuteInEditMode]
public class PackageManagerAddExample : MonoBehaviour
{
    AddRequest m_AddRequest;
    
    void Start()
    {
        Debug.Log("Client.Add example...");
        m_AddRequest = Client.Add("com.unity.textmeshpro");
    }

void Update() { if (m_AddRequest != null && m_AddRequest.IsCompleted) { if (m_AddRequest.Status == StatusCode.Success) { var package = m_AddRequest.Result; Debug.Log($"Added package: {package.name}" + $"\nVersion: {package.version}" + $"\nDisplay name: {package.displayName}"); } else { Debug.LogError($"Add failed: {m_AddRequest.Error.message}"); } m_AddRequest = 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: