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

Resolved Prevent compiling when automaticly adding packages

Discussion in 'Scripting' started by IedSoftworks, Jul 9, 2022.

  1. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    PREVIOUS TITLE: Temporarly disabling compiling during automatically adding packages

    Hello,
    I'm currently making a little script, that reads a file that contains all the packages I want to add and then adds them one by one. It contains normal unity packages, OpenUPM (what is handled differently then everything else), GIT-packages and actual folders.

    My problem is that everytime I add a package Unity (over PackageManager.Client.Add) auto loads and complies and breaks my script in half.
    Is there a flag I can set to prevent Unity to compiling until I want it to load and complie everything?

    iedSoftworks
     
    Last edited: Jul 9, 2022
  2. bgulanowski

    bgulanowski

    Joined:
    Feb 9, 2018
    Posts:
    35
    Only thing I can think of is to run your script outside of Unity, with Unity not running.
     
  3. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    Hi, thanks for your response.
    Sadly that doesn't work, since I'm using Unitys API to display a window, what exactly its gonna add and to actually resolve and add the Packages.
    While I was already thinking about editting the manifest.json by myself, I ran into the problem on how to get the package.json of a GIT-repo without having to download the whole repo. Everything else is fairly easy.

    One thing I want to try is removing the async keyword from my script. Maybe that prevents the system from automatically loading the new stuff.
     
  4. villevli

    villevli

    Joined:
    Jan 19, 2016
    Posts:
    86
    I think Unity will not start the compilation until you return control to Unity.
    By returning control I mean one of these things:
    - returning from the Unity method (OnGUI, InitializeOnLoad, etc.) that triggered your script
    - yield returning in a coroutine
    - awaiting in an async method

    So if you make sure you add all the packages in one method that does not return or yield it should be possible to do it in one go.
     
  5. IedSoftworks

    IedSoftworks

    Joined:
    May 27, 2021
    Posts:
    12
    Yeah. I found my issue.
    I believed I should use a async function with Task.Yield for my importing, so non of the rendering and stuff gets interruped.
    Now I have removed the async keyword and set the window I show before actually importing (so the user can see, what gets imported and what not and can prevent that if he f.E. selected the wrong file) as modal.

    And now it works flawlessly.

    Lessons learnt: Do not do Client.Add in a async-function :D