How to share c# source between Unity projects?

We have two projects underway and want to share some classes between them. The shared source must be in a single location so when a programmer on Project1 updates the code those changes are immediately seen in Project2.

The important part is that we do not want to maintain multiple copies of the same code. i think we would agree that its simply bad practise to do so.

The only option appears to be putting the code in a class library and load it as a plugin into each project. But I don't believe this works when referencing Unity types like GameObject or transform.

In C/C++ land we could put the source in a directory and include it into any solution we wanted - doesn't seem to be so easy in Unity-land. Is their a better way to share code between unity projects?

EDIT: All projects, including the shared code, are already under source control. This is not a Source Control question, its a framework issue. (And obviously I need to write better questions!)

Lets say the directory structure looks like this...




Can Unity reference code from other projects? Can Unity reference code outside of its own Assets folder? If so, how?

You can share code (and assets like prefabs) effectively like this:

Use external versioning support. (I'll use subversion in this example, but most versioncontrol systems support this scenario).

Version your game at:


Version your shared code at:


Now, in the checkout of the game, create a folder called "SharedCode", and set its svn:external property to the svn url of your shared code svn location.

This way you can easily share your "common" code amongst different games. If your needs get a bit more complex, you can also branch your sharedcode project to something like:


if you want to "freeze" the version of the sharedcode that the monkeydonkey game uses. (for instance, when a game gets close to shipping, but you have another game in full production, it's likely that you don't want to the sharedcode updates to be picked up by your almost shipping game, due to risks of accidentally introducing a bug).

I find this to work pretty well myself, as you can easily commit changes to both your game, and the engine code.

You could also try Projeny - a free open source framework that addresses this problem for both assets and scripts (using symlinks)

Found a step by step guide on sharing Unity3D code between projects using a combination of Gits’ submodules and symlinks:

The link provided by @Cyclops may provide part of the answer. Sharing the code could be accomplished through a clever use of source control.

Your scripts (and potentially the whole project if you have pro) should be under source control already. Consider moving all shared code into a single root folder. Keep this folder out of your source control by ignoring it. Create a new repository just for this shared code.

With this model, you can develop in both projects making changes to project-specific and shared code. The only extra work comes when its time to check-in and sync your changes to the server. Instead of only doing it once, you'll do it for the project specific repository and the shared one.

When working on either project, always remember to check out the latest version of the shared code and you should have a single point for managing all that code.

I found a really nice way to share code,perfab and any others in different unity project, yes, that is SVN indeed,
see here
we can create a new project using svn, then in the unity project, just set a folder property to svn:externals and link to our porject we created
and we must use the svn as the version control system.not the asset server provided by unity

that’s really a nice method

The solution I came up with doesn’t use DLLs or SVN.

-Make a new project, and add your shared scripts etc

-Grab Belvedere, a free automatic file manager

-Add the scripts folder to Belvedere, then create a rule for each project that says any file date last modified 1 second ago, copy them to a location in your project. The result is when you modify any of those shared scripts, or add new scripts, all your projects will be automatically updated.

-Whenever you start a new project, simply add a new rule to Belvedere, and watch your shared files populate your new project.

It works quite well!