Error in Package Manager when trying to add a package from batchmode

Hello everybody!

I’m trying to install a specific package from batchmode through an editor script with unity 2019.4.0 using a command like this:

"PATH TO EDITOR EXECUTABLE" -quit -batchmode -buildTarget Android -projectPath "PROJECT PATH" -targetBuild Android -logFile "Log.txt" -executeMethod HandlePackages.AddOculusSupport.

If I use the same script from editor “HandlePackages.AddOculusSuppor” the package is successfully added, while in batchmode nothing happens.

I noticed that when I try to add the package from batchmode the log file generated from the execution of the script shows me just one error and none of the debug messages I inserted in the method that should add the package.

The script:

public static class HandlePackages
{
    static AddRequest Request;
    static RemoveRequest removeRequest;
    static string oculus_package = "com.unity.xr.oculus";
    static string oculus_pk_version = "@1.3.4";

    [MenuItem("Window/Add XR Managment")]
    public static void AddOculusSupport()
    {
        // Add a package to the project
        try
        {
            MakeTheRequestAsync();


        }
        catch (Exception ex)
        {
            throw ex;
        }

    }


    public static async void MakeTheRequestAsync()
    {
        Request = Client.Add(oculus_package+oculus_pk_version);
        EditorApplication.update += Progress;
        while (Request.IsCompleted)
        {
            Debug.Log("request not completed");

            await Task.Delay(1000);
        }

        Debug.Log("request done");
    }


static void Progress()
    {
        if (Request.IsCompleted)
        {
            Debug.Log("Request completed");
            if (Request.Status == StatusCode.Success && Request.Result.name.Equals(oculus_package + oculus_pk_version))
            {
                Debug.Log("Installed: " + Request.Result.packageId);
          
                return;
            }
            else if (Request.Status == StatusCode.Success)
            {
                Debug.Log("Installed: " + Request.Result.packageId);
            }
            else if (Request.Status >= StatusCode.Failure)
                Debug.LogError(Request.Error.message);

            EditorApplication.update -= Progress;
        }
    }

While this is the top 2 lines of the Log.txt printed by the CLI

[LicensingClient] ERROR Failed to connect to local IPC
[Licensing::Module] Failed to connect to channel: LicenseClient-myname

I find that I have an error also in the “upm.log” :

[2021-10-06T15:41:29.320Z][INFO] Starting Server

[2021-10-06T15:41:29.331Z][INFO] Server started on port [59408]

[2021-10-06T15:41:38.374Z][ERROR] [Unity Package Manager (Upm)]

Parent process [38216] was terminated

                    [2021-10-06T15:41:40.330Z][INFO] Resolving dependencies by depth

[2021-10-06T15:41:41.194Z][ERROR] [Unity Package Manager (Upm)]

Parent process [9068] was terminated

I think that must be some problem with the package manager, so I tried out all those things written here Batchmode, how do you write to the console, so the user knows when it is done? with no success (even though I didn’t try to run the script with unity 2020)

EDIT:
I tried to lunch that script also in an empty project with unity 2020.3.13f1 with no success

What else can I do to fix/debug this problem??

Hey!

From speaking to the team, they don’t believe this is an issue with Package Manager but rather a problem with the way “-executeMethod” works in batch mode and potentially the way it works (or doesn’t work) with “async” functions.

It’s just a hunch but maybe what’s happening is as Unity launches, the static AddOculusSupport function executes but the async MakeTheRequestAsync function doesn’t run to completion. Although we would still expect to see one occurrence of Debug.Log(“request not completed”); in the logs if that were the case.

Unless the async function doesn’t even begin executing in batch mode… As for the upm.log, all we’re seeing is “Parent process [9068] was terminated” which is just UPM saying that Unity was closed.

I would recommend that you do some more debugging and see if you can get any async code (like printing “Hello world” in the log) to run from batchmode.

If async is the problem and you’re able to see logs with a regular static function, you should consider using Thread.Sleep() to wait for the Packman request so everything is handled in a synchronous manner :slight_smile:

Thank you for your reply, at the end of the day I changed completely approach and now instead of adding/removing the oculus support I enable/disable it through the XRSetting ScriptableObject.

Although If I will have time I will try to test the old script again using Thread.Spleep()

You can also remove the quit parameter and then exit yourself through EditorApplication.Exit(); once you’re finished. Here is an example of upgrading all packages automatically: UnityWebGL-LoadingTest/Assets/Scripts/Editor/UnityPackageScripts.cs at master · JohannesDeml/UnityWebGL-LoadingTest · GitHub

Hope that helps you (and others that are searching for that topic) :slight_smile:

1 Like