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. Dismiss Notice

Add/Remove packages as part of a build script

Discussion in 'Package Manager' started by tom_e_roberts, Nov 18, 2020.

  1. tom_e_roberts

    tom_e_roberts

    Joined:
    Jul 19, 2017
    Posts:
    29
    Hi all,
    I'm trying to add/remove packages in a new build system I'm making.

    I'm using Client.Remove and Client.Add to remove and add packages respectively.

    As it's a build system that might be applied from command line, it should be able to do it in one call. However I'm hitting errors where I remove packages (like ARCore package) and it still has compile errors related to the ARCore package, despite it being removed.

    Here is some snippets of the code (the entire system is a few files, so a bit much to put it all in here)
    To remove a package:
    Code (CSharp):
    1. RemoveRequest removeRequest = Client.Remove(packageToRemove);
    2. removeRequests.Add(removeRequest);
    Then to wait for the request:
    Code (CSharp):
    1. while (!removeRequests.TrueForAll(request => request.IsCompleted))
    2. {
    3.     //Wait
    4. }
    Pretty much the same happens for Add packages

    My tldr question is, is there a way to add and remove packages synchronously within an editor call before a build?
    I'm currently using Unity 2019.3.15f1
     
  2. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    151
    Hi @tom_fv,

    It looks like your code is first starting a bunch of requests and then waiting for them all to complete. Concurrent requests like this aren't properly supported yet. The safest approach would be to make a queue where each request only starts once the previous request has completed. FYI, we are currently working on ways to add and remove multiple packages in a single operation. It sounds like this would be quite helpful for you!
     
    UnityMaru likes this.
  3. tom_e_roberts

    tom_e_roberts

    Joined:
    Jul 19, 2017
    Posts:
    29
    Thank you for the reply, yes that would be quite helpful :)
    So far I have got it so it can continue the build after a package import by using EditorPrefs to save the state before a compilation as started and checking that EditorPrefs on InitializeOnLoad. Though it would be good for someway to persist certain script executions between compiles, I understand that could be a difficult thing to acheive in the current compilation pipeline
     
    UnityMaru likes this.
  4. KBaker46

    KBaker46

    Joined:
    Feb 19, 2021
    Posts:
    2
    Hello @samuelb_unity, is there any update regarding the feature you talked about?
     
    EthanFischer likes this.
  5. matheus_inmotionvr

    matheus_inmotionvr

    Joined:
    Oct 3, 2018
    Posts:
    56