Programmatically create the upmconfig file

Hello, we are making use of the scoped package capabilities of Unity, but our NPM packages are private. Therefore we need the upmconfig file to contain the token for Unity to download the imported packages.

However, we don’t want every person to have to create this file on their computers. For example, our artists should not have to deal with this at all.

So I would prefer one of 2 solutions here, which it does not seem like Unity supports at the moment, but maybe I haven’t found it?

  1. Specify per project basis where Unity should look for the upmconfig file. If this was a possibility, then we could simply point the path inside the project itself and include the upmconfig file with the project.

  2. Have a piece of code run BEFORE the package import begins. This piece of code could then create the upmconfig file on the user’s computer. I have not had any success executing code at this stage though.

If anyone has any way to accomplish this, please do tell, because it would be a big endeavor to have all our developers have to set up this file to open our projects.

1 Like

Hey there :slight_smile:

The team informs me that the second solution could be done by using InitializeOnLoad, which should be called before & after the resolution process. (Unity - Manual: Running Editor Script Code on Launch)

But this solution requires the code to actually compile successfully first, right? But in our case it won’t, since the UMP file does not exist, and as such, parts of the code cannot be imported into the editor. Or am I misunderstanding something?

Hi, it is possible to isolate a portion of code from the main assembly by creating an assembly definition file in a sub-folder. This would ensure the code within the sub-folder is always compiled and ran, even if most packages are missing. You could place your file creation logic in there. One downside of this method is that you will see a lot of errors the first time you open a project after a fresh clone, you will probably need to force a resolve operation from within the code after you’re done creating the file.

Another workaround would be to distribute a batch or a shell script to create the file with your project. Your team members would have to remember to execute the file at least once after a fresh clone, but then the project should open without errors.

Yeah, that is basically the solution we came up with in the end, its just a shame there does not seem to be a way to avoid showing that popup that occurs when importing of packages fail.
We opted to close the application to force a resolve of the packages, but Client.Resolve seems like a much better approach, so we will implement that instead! Thanks.

But is there a way to not show that dialog when importing packages? That would be great.

When was Client.Resolve added? We are on Unity 2019.4.13. Is this method added in a later 2019LTS version?

But is there a way to not show that dialog when importing packages? That would be great.

Do you mean the Safe Mode prompt? You can disable this dialog in Edit > Preferences > General > Show Enter Safe Mode Dialog. If you disable the dialog, Unity automatically enters Safe Mode when it opens a project with compilation errors.

When was Client.Resolve added? We are on Unity 2019.4.13. Is this method added in a later 2019LTS version?

This method has been available since 2020.1. You should get the same result by calling AssetDatabase.Refresh() in 2019.4.

By dialog, i mean the dialog that shows up saying that authentication has failed for importing packages. There is then 3 options, Abort, Retry or Continue.

Hi,

There is no way to skip this dialog that I am aware of, apart from launching the editor in batch mode.

I’ll discuss the possibility of having a per project configurable path for the upmconfig file with the team. Meanwhile, generating the file from outside the editor might be the only workaround to avoid the errors on the first startup.

Alright, thanks for your help. Having the upm file path configurable in the project settings would be of great help!

While discussing packages, would it be possible to have Unity include its own portable version of git, so we do not need to make our artists install git on their computers manually when we target GitHub commits in the manifest.json file?

I wanted to bring this topic up again since it’s still relevant for organizations that use private registries: Is it now possible to hook into the package resolve step when a Unity project opens so that I can show a popup that prompts the user to login to our private registry? Without the authentication, the project will fail to load required packages and not compile, and we also don’t want to force users to execute a special script before opening the project, because there will always be users who don’t know or forget. Ideally, Unity would provide us with a way to prompt users for login data before the project starts to resolve packages.

Hi @Xarbrough_1 , thanks for the feedback! I would suggest submitting the request to our public roadmap, which can be done going to https://unity.com/roadmap/unity-platform/pipeline-integrations

On the Roadmap section of this page, select the Package Management tab, scroll all the way down to the last card, “Submit a new idea!

1 Like