Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Adding a Custom Package Using a Script to a Project

Discussion in 'Package Manager' started by Proroke, Apr 16, 2023.

  1. Proroke

    Proroke

    Joined:
    Apr 16, 2023
    Posts:
    2
    Here is a script with a link to a custom package but it doesn't want to be added to the project. What is the problem ?

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.PackageManager.Requests;
    3. using UnityEditor.PackageManager;
    4. using UnityEngine;
    5.  
    6. namespace Unity.Editor.Example
    7. {
    8.     [InitializeOnLoad]
    9.     static class AddLibrary
    10.     {
    11.         static AddRequest Request;
    12.  
    13.         [MenuItem("Window/Add Library")]
    14.         static void Add()
    15.         {
    16.             // Add a package to the project
    17.             Request = Client.Add("file:\\C:\\Users\\111\\Desktop\\com.prorok.testpack");
    18.             EditorApplication.update += Progress;
    19.         }
    20.  
    21.         static void Progress()
    22.         {
    23.             if (Request.IsCompleted)
    24.             {
    25.                 if (Request.Status == StatusCode.Success)
    26.                     Debug.Log("Installed: " + Request.Result.packageId);
    27.                 else if (Request.Status >= StatusCode.Failure)
    28.                     Debug.Log(Request.Error.message);
    29.  
    30.                 EditorApplication.update -= Progress;
    31.             }
    32.         }
    33.     }
    34. }
     
  2. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    490
    Hi @Proroke,

    The problem is likely the leading "\\" after "file:". The proper string would be
    "file:C:\\Users\\111\\Desktop\\com.prorok.testpack"
    .
     
  3. Proroke

    Proroke

    Joined:
    Apr 16, 2023
    Posts:
    2
    Thanks