Building your own libraries to share amoung unity projects.

Hello all!
So basically the idea is to build some tools I would like to be totally independent from game code (and even to be sold in the asset store): e.g.: SQLite functionalty, math functions, etc. I have thought to build each tool as a managed dll that latter if I need in a project I just add the dll to the unity project’s corresponding plugin folder.

But maybe there’s a better way or you have any advice.

Thanks in advance!

You can do dll’s.

Or if you want to share the source code, you can just create a project with the functionality written in it. And then export it as a ‘Asset Package’.

I used to do a dll for our ‘spacepuppy framework’ (a collection of code we carry from project to project):
5773048--608578--upload_2020-4-27_15-40-43.png

In our most recent 4.0 version I moved to doing it as an asset package:

Exporting:

5773048--608584--upload_2020-4-27_15-42-6.png

As for copying them into projects. I usually create a batch scripts. I have a batch script for “initializing” a project, which just lays out the needed files in a clean project and creates yet another ‘update’ batch script for easy one click updating. (this was in the ‘dll’ versions).

With unity asset packages, it actually deals with a lot of the stuff that these batch files did. And I can just “Import Package” instead.

The only big consideration between the 2 is if you plan to share. Dlls vs source code. Though of course the ‘asset package’ can contain dll’s (but of course now you have 2 layers of building the dll and then building the asset package).

1 Like

You can setup packages locally and use them like packages in the package manager. This will also allow for easy release onto the asset store and allow customers to install via the package manager.

3 Likes

Yeah I just export packages too. I prefer not to use DLL’s primarily because I sometimes need to make a change to the package to accommodate the project in some manner, and turning my own code into a DLL makes that an unnecessary hassle.

Note that this has a big issue of a poor support for local dependencies.

You can depend on a local package in a project.
It is impossible to import a local package in a package.

This may or may not be a problem (in my case I went back to manual implementation of package system allowing for local dependencies[0])

[0]it sounds smart, but it is a script with some cp calls

1 Like

I’m pretty sure you can make packages rely on other packages…?

But yes, not totally flexible.

Yes, as long as dependency is referred by version. Referencing git repository or location on disk (local packages) is not supported.

i have two different project in unity with some common scripts in both project. Now in second project did some changes in those common script in implementation according to project functionalities. Now i want a common way to merge the changes i’ll make in first project are automatically comes in second project.

I want changes done originally in the second projects as it is and new changes i made in first project combine.
Try to use gits but both project are different so.

Can anyone help me with this ?

You might just want to follow the instructions on making a custom package as was linked above: https://docs.unity3d.com/Manual/CustomPackages.html

I’ve personally used a separate project for my common code and define a custom package inside it with a package.json. Though I host them privately on github and install them into my projects via a github URL. When I need to make an update, I open up the project, make the change, commit and push the changes on github, then other project can just update their Package Manager version. I don’t believe there’s a way to do auto-updates.

They all have assembly definitions. Any dependencies on Unity packages or other packages is done through defines symbols: https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html#define-symbols

That’s my workflow. I’m sure other folks have their own.

1 Like