Setting up a Framework Directory

The first step to creating a great reusable development framework is to have a way of effortlessly sharing code across multiple projects. This is a little trickier than one might expect in Unity. Assets need to be a part of the project directory to be usable. Initially, I tried to follow the Asset Store model, exporting reusable assets as a Unity package and importing that into new projects. Unfortunately, this was a maintenance nightmare. Every minor update required a new export and a gaggle of imports.

I decided a better approach was to use symbolic links. This allowed me to maintain a single Framework folder, and with a tiny bit of setup, for that folder to appear seamlessly in all of my Unity projects.

Here’s how it works:

First, create a folder somewhere outside of your Unity project(s). I keep mine at the top level of my GitHub directory, right alongside my Unity project folders. Call it something catchy, like Framework.

Next, we’re going to add the folder to a project with a symbolic link, or junction link in Windows. This creates an alias to the Framework folder, essentially tricking the OS (and Unity) into believing that the external folder is under its hierarchy. The syntax for this looks like the following:

mklink /j "<path to unity project>\Assets\Framework" "<path to framework>"
cd <path to unity project>/Assets ln -s <path to framework>

Here’s what this looks like for my new “Sandbox” project and existing Framework:

framework cmd

Execute the command to create the junction…

framework cmd success

It worked! Now the Framework folder shows up in Unity like any other:


The illusion is so complete, Unity even generates a .meta file for the Framework folder. Any changes to files in this folder will resolve to changes in the Framework folder (instead of your project folder) in Git, exactly as we’d like. Configure all of your projects this way, and you can simply and easily maintain a suite of shared code among many different projects.

Bookmark the permalink.

Comments are closed.