3
\$\begingroup\$

My assumption is that, in any context , it is not a good practice to keep libraries and packages in your source control.

For instance, I have downloaded the "Platformer set" asset and imported it into my Unity project. It goes by default into ./Assets, but I have moved it into ./Assets/Packages, folder which I have added to my repository's .gitignore file. This way I plan to differentiate custom assets (part of my source control) from public ones (which I plan to import on a second computer upon mapping the repository).

I have taken one of the tilesets in "Platformer set", sliced it, and created a tile palette.

Then I have used the tiles in the tile palette to edit a tilemap, building some platforms.

Finally, I delete the imported "Platformer set" found under ./Assets/Packages folder, since I would have the same result mapping my repository in a second computer (because ./Assets/Packages is not part of my source control).

My idea then would be to import the package again through the package manager, and move it to the right location. Unfortunately, at the very moment I delete the asset folder, the tilemap looses all the tiles related to that asset. Similar things would happen with animations created on imported asset's sprites, and many other types of assets.

So, long story short: which is the right way (if it exists) to be able to exclude Unity assets from your source control using Git, but avoiding messing up with your project files? I come from a C# application background where broken references remain there until you fix them, they don't dissappear.

Or should I keep the packages in the source control? A second developer mapping the Unity project with git would have these packages downloaded onto their machine as part of the mapped Unity project, even if they don't have them downloaded using their package manager in the first place (which makes you end up with a weird development environment, taking into account that the normal workflow is that you FIRST download them with the package manager into a common location in your PC and THEN you import them into your project).

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think you need to clarify exactly what you’re trying to achieve and what exactly is going wrong. For example, It’s a bit hard to understand why you’re deleting the package, and why you’re wanting to git ignore it in the first place. Maybe some extra details will help. \$\endgroup\$
    – Adam B
    Commented Oct 18, 2021 at 4:41
  • \$\begingroup\$ Maybe I am misinterpreting something since I am fairly new to Unity, but I don't think it is a good practice in any technology or programming language to keep libraries/nugets/packages/etc. in your source control. Again maybe it is common practice to include them in the case of Unity, that is my question. I have updated the question to clarify this, thank you. \$\endgroup\$
    – Silverman
    Commented Oct 18, 2021 at 16:41

1 Answer 1

1
\$\begingroup\$

For packages (not assets), you should include your project's Library folder in the .gitignore. Unity has a manifest.json file in the packages folder (that should be in your repo) that will tell it which packages to install locally.

For Assets, (not packages), unless the license forbids it, I keep them in source control if possible. This makes everything way easier. It keeps projects in sync easily between computers and makes the project loadable from everywhere. For Assets that are too big, I use git LFS (large file storage). If the license forbids it, I first try to not use that asset, or if that asset is absolutely necessary, I try to hack together some weird solution, often involving .unitypackages in some form (they keep GUIDs consistent).

For custom packages, I set up a private passworded Verdaccio package server on my google cloud, and then point unity's package manager to that server so I can sync my own content between unity projects outside of git. When switching computers, I just have to log into the server once, and unity remembers the login token for the private server.

Edit: Just to add, many of my custom packages contain assets themselves. This is fine.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .