Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Building your own libraries to share amoung unity projects.

Discussion in 'Scripting' started by Jorhoto, Apr 27, 2020.

  1. Jorhoto

    Jorhoto

    Joined:
    May 7, 2019
    Posts:
    99
    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!
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,578
    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):
    upload_2020-4-27_15-40-43.png

    In our most recent 4.0 version I moved to doing it as an asset package:
    upload_2020-4-27_15-41-45.png

    Exporting:

    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).
     
    Jorhoto likes this.
  3. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Joe-Censored, Jorhoto and lordofduct like this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
  5. matkoniecz

    matkoniecz

    Joined:
    Feb 23, 2020
    Posts:
    170
    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
     
    Jorhoto likes this.
  6. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I'm pretty sure you can make packages rely on other packages..?

    But yes, not totally flexible.
     
  7. matkoniecz

    matkoniecz

    Joined:
    Feb 23, 2020
    Posts:
    170
    Yes, as long as dependency is referred by version. Referencing git repository or location on disk (local packages) is not supported.
     
  8. NirmalGhadiya

    NirmalGhadiya

    Joined:
    Jan 24, 2018
    Posts:
    11
    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 ?
     
  9. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,224
    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.
     
    CodeRonnie likes this.