Wednesday, 6 April 2016

Share Assets between Unity projects on OS-X

Unity's packaging system doesn't help much with keeping copies of the same assets in sync across projects. Over time this becomes a productivity killer which encourages copy-pasting assets everywhere. Fortunately, OS-X and Windows both allow using low level shared folders.

This article deals with sharing assets on OS-X to use across Unity projects. Using this stratagem, we make up for Unity's shocking lack of a class path, what were they even thinking.

First create a new git repository. Then, add the files that you want to share. Don't put unity projects in there, only assets.

We now share this to a Unity Assets folder using a symlink. A symlink is not an alias. Use Terminal to define a symlink, like this:

ln -s path/to/original path/to/Assets/name_of_original

where:

  • path/to/original is the root folder for your shared assets.
  • path/to/Assets/name_of_original is the 'alias' giving access to shared files.


Repeat the same for all projects where you want to share this. This can be tedious; fortunately there is a trick: although a symlink is not an alias, symlinks can be duplicated and renamed in the Finder!

What happens in Unity?

Unity will display a warning when detecting the sym-linked folder. It's telling us that issues may arise if projects using inconsistent Unity versions use the same asset.
Better than not being able to use them at all.

How does version control view a symlink?

Both Git and Mercurial view our symlinked-folder as a file that can be either ignored or checked in. I opted for checking the files in (because Unity creates meta for these and meta are, for the better and especially for the worse, the wet dirt that holds Unity projects together.

Overall this works pretty much as we want it to - we're managing shared assets separately from the project we are linking from.

No comments:

Post a Comment