Search Unity

How to define custom packages as readonly?

Discussion in 'Package Manager' started by Carpet_Head, Jan 20, 2020.

  1. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    In the Unity editor it is impossible to make changes (intentionally or unintentionally) to packages distributed by Unity. Is it possible to set up user-created packages (particularly local packages) in a similar way? for example so that changes are greyed-out in the editor?

    Ideally this will also do whatever magic marks the code as read only in Jetbrains Rider too
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Place your package outside Packages or Assets folder. And install it via the "Add package from disk..." feature. Basically packages installed via git URL, file protocol or registry are read-only.

    Not sure things about Jetbrains Rider though.
     
  3. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    Unfortunately this doesn't work - it seems like no matter where you store the file (2019.3.0f5) with "Add package from disk..." it is always considered read/write enabled

    This solution would be perfect if it did work

    I don't think we will go with git or registry for workflow reasons
     
  4. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    It works for me tested with 2019.30f3

    I checkout this package to the same level to Assets or Packages.
    upload_2020-1-20_21-2-24.png

    Add via file protocol.
    upload_2020-1-20_21-3-36.png

    Point to the package.json, which is read-only (grey out)
    upload_2020-1-20_21-4-18.png
     
  5. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    are they definitely the same package? in the manifest.json it references com.littlebigfun.addressable-importer, but the inspector screenshot shows com.unity.addressables

    for example my configuration looks like this
    upload_2020-1-20_13-9-24.png
    and does not appear greyed out in the editor
     
  6. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Oh, my mistake. You're right. Local packages are mutable.
     
  7. felipemunoz_unity

    felipemunoz_unity

    Unity Technologies

    Joined:
    Apr 5, 2019
    Posts:
    15
    As far as I know, packages are flagged as "immutable" when:
    • They come from a remote source such as a registry or a git repository
    • They are loaded directly from a .tgz (file reference to a .tgz path)
    Local packages are indeed mutable
     
  8. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    Then I guess it is a feature request to give us the ability to make a package immutable? For example if a package is shared between two projects you don't want someone to unintentionally change one, breaking the other

    Without the pain of having to make a .tgz every time you want to make a change
     
  9. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    I'm also struggling to find any information on how to make a tarball package compatible with local loading (still with a preference to not require this step)
     
  10. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
  11. Carpet_Head

    Carpet_Head

    Joined:
    Nov 27, 2014
    Posts:
    258
    I'm struggling to figure out how to arrange the files inside the tarball rather than how to make one itself - I had a quick go but unity didn't recognise the package with any of the obvious ways to arrange it
     
  12. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Move files to a folder named package, or simply run `npm pack`.

    upload_2020-1-28_12-42-26.png
     
  13. darger

    darger

    Joined:
    Aug 30, 2012
    Posts:
    17
    It is convenient to be able to edit the source code of a local package, but there are cases where there are problems.
    If the imported local package mistakenly contains the same assets as the project and a metafile conflict occurs, the metafiles GUID on the local package side will change. This is an annoying behavior.
     
  14. NathanJacobs

    NathanJacobs

    Joined:
    Jul 27, 2020
    Posts:
    2
    So it seems tarball packages are not actually immutable like the packages from Unity. I created a custom local tarball package, but I can still modify any script file and the changes in fact persist. This is not the same behavior as packages from Unity, where the changes are immediately reverted.

    Any insight from Unity would greatly be appreciated.
     
    JakobAnarkyLabs likes this.
  15. JakobAnarkyLabs

    JakobAnarkyLabs

    Joined:
    Jun 30, 2021
    Posts:
    2
    I agree with @NathanJacobs
    It is strange that we are able to change a script (the locally cached version in Library) in a local tarball package, and that the changes persist. I can't think of any reason why that should be the intended behaviour.

    What do you say @felipemunoz_unity?