Managing dependencies that are other unity projects?

Hey, guys!

It’s worth mentioning that all of my projects are git repos. Now:

TL;DR
I’m looking for a way to deal with project dependencies that are other unity projects and be able to:

  • Pull all changes I’m interested in (in my case, everything in a subfolder of the Assets folder and the Resources folder)
  • Be able to work on the dependency’s repo (make local changes and submit them)

Long story:
I have a little UI framework I’d like to import into my projects but keeping the ability to commit changes to it when needed (since it’s a new thing, lots of new use cases will arise as I use it so this is a must for my own sanity), which means unitypackages won’t do the trick here.

My first thought was to use a git submodule but this would clone the entire repo and not just the folder where the code is, which isn’t really nice.

I also found out about sparse checkouts and this might kinda do the trick as well (haven’t tried to add a repo cloned this way as a submodule).

I managed to clone the entire repo, change its root (with filter-branch, I don’t really know how this is gonna behave if I need to work with branches) and then add it as a submodule and it seems to be working. The only problem I have left is that the code in the dependency’s repo relies on stuff placed in the Resources folder, which I’m not able to pull this way. This is manageable but I’d like to try and find a way to unify how I manage both things.

Thank you for any insights you might bring into this!

Just symlink locally, maybe?

Yeah, I thought about something like but wouldn’t that be a bit inconvenient?

Unless I’m missing something, I should clone the project wherever I want and then have symlinks for the folder where my code is and each file in the dependency’s Resource folder that I want to use.

I guess I could write a bash script to do that, but the setup would be a bit too much tedious. I would not have to manage the Resources folder separately, though, so I definitely won’t discard that.

It depends on how you set up your dependency projects. If you keep them arranged like an Asset Store package should be I think it could work (Package Name/ and Package Name/Editor/ folders). Then you simply link the repo folder to Assets/Plugins/ in the project which depends on them. See this increasingly popular post.

If you’re as lazy as me you’ll write a drag and drop tool you can drop the new Unity project’s folder on, which then presents a list of repo folders to check and link automatically. But this is the hardcore option.

Hey, heads up.

Fist of all, thank you for sharing that post with me. I had no idea about those guidelines and they’ll sure become useful.

Secondly, I’ve been told that Resources folder are “merged” when building pretty much like the “Editor” (which I was not aware of).

Those two pieces of information (assuming the “Resources” folder thing actually works) on top of what I have already built should be enough to have a decently organized and comfortable way to work with dependencies.

I’ll post once more in this thread after I figure it out and I’m satisfied with my setup in case someone else googles this or something.

A trick for a quick start: Make a package with a folder hierarchy, default scene and a canvas. Sprinkle with other things you always use. Import when starting new projects and link in stuff as required.

Update: left the problem hanging for a while and tackled it again today. I kinda figured it out.

For starters, I ceased to use the Resources folder to instantiate my prefabs and I now use the AssetDatabase class. This allows me to put my prefabs wherever I want.

Secondly, I now make a repo with the code I want to reuse only and not the whole project. The project I use to work on that code separately is just an empty project with this repo cloned somewhere inside the Assets folder.

Lastly, I import my dependencies as submodules in the main project and it works just fine so far.

I’ll probably write a tutorial and post it somewhere in the near future (like next week or something, after giving it some time to have a couple of problems with my teammates :stuck_out_tongue: )

Thanks everyone for your help :slight_smile: