How to define custom packages as readonly?

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

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.

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

It works for me tested with 2019.30f3

I checkout this package to the same level to Assets or Packages.

Add via file protocol.

Point to the package.json, which is read-only (grey out)

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
5389638--546534--upload_2020-1-20_13-9-24.png
and does not appear greyed out in the editor

Oh, my mistake. You’re right. Local packages are mutable.

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

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

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)

See this https://medium.com/openupm/unity-package-manager-2019-3-round-up-8a663ad06bfe (search tarball)

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

Move files to a folder named package, or simply run npm pack.

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.

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.

1 Like

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 ?