How to prevent library to keep rebuilding itself with external version control?

This issue is about 2 years old now (for me). Current answer is: can’t be done.

I’m using git, but I believe this doesn’t depend on which one you’re using, even if it’s Asset Server.

Keep in mind I’m following everything in the manual plus what I’ve found around.

The library rebuild can take anywhere from minutes to even hours, depending on how much Unity thinks it needs to work.

Although this is not a critical issue (it doesn’t stop the workflow) it’s still huge.
We’re not fully using git thanks to this issue. It’s impractical to go back in history to an old commit or even simply changing a parallel branch can become a nightmare. So we always avoid to do it, unless it’s critical.

There are many things that will trigger a library rebuild, here are a few known ones:

  • Touching the file. No brainer here. The more you touch, the more time it takes.
  • Moving / renaming files outside of Unity. Specially noticeable if they are video files.
  • Keeping timestamps in git is not enough. At least in the way I could do it.
  • Whenever we checkout in a new machine - this will add an extra library rebuild because eventually have to change back the build platform settings to Android or whatever.

The question is in the title: How to prevent the library to keep rebuilding itself like that?

As for plausible expected answers…

I know it wouldn’t work if I commit the library along because even just checking out an old commit and back to same one before opening Unity, it will also trigger a library rebuild.

The “Library Network Cache” called “Cache Server” does not solve any of these issues. It does make it faster, some times, specially for checking out on a new machine. But it’s still far from good. It still can take up to hours.

Summary: don’t let your version control system rewrite history or re-perform changes that were previously made.

Unity will always reimport assets if their timestamp changes. If you want to make a backup of your project to in case of accidental re-imports, you must copy all folders as well as timestamps. Windows/OSX copy functionality does not preserve timestamps, so you will need to use a helper application. (In OSX terminal or Cygwin, “cp -a” does the trick.)

When you check out on a new machine, the build platform isn’t specified because you haven’t checked that file in. Do it and you’ll never have this problem. To find out where the platform build settings are stored, make a small project, change the build platform, and see which files changes. It’s in Library/ or ProjectSettings/.

Here’s a trick about using Git and avoiding reimports: Always keep a project backup (and backup when in a state where Unity doesn’t need to re-import anything). If you do some Git operations (like svn dcommit or rebase) and your file tree ends up mostly the same as it was before besides that the modification times have changed, you can salvage the situation: use a syncing program like rsync to copy your whole project backup (except the .git folder) over your main project, deleting any differences (rsync -a --delete). At this moment, your recent changes will not be reflected in the working copy, so use “git checkout” and maybe “git clean” to iron out the differences. Now when Unity is opened, it will only re-import the files that are actually different, regardless of any changes that may have been done and undone.

Also, if you must rename an asset, do it within Unity and not the filesystem. That way Unity knows it doesn’t need to re-import. (Your coworkers will still need to re-import that file/folder, so do this sparingly.)

It seems Unity 3.5 no longer supports files that begin with a period (a “.”) so a filename such as “.somefile.prefab” will cause Unity some to have some issues.

The fix for this is to rename your file so that it no longer begins with a period.

Specifically I was having this problem with 2D Toolkit which creates a file called “.tk2d.prefab”. Renaming this file to “-tk2d.prefab” and fixing up the tk2d codebase so that it loaded this file instead resolved the issue for me.