Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best practice on sharing code between projects?

Discussion in 'Scripting' started by Mullan7, May 1, 2019.

  1. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    I find myself copying and pasting a lot between projects. Or exporting packages with systems in them.

    I would like to maintain a library with scripts that update in all of my projects at once so I can have a framework of sorts.

    What's the best way to do this? I've seen git submodules and symbolic links suggested. What's the best practice?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    I personally maintain a separate visual studio project, and when I update it I have build scripts that compile it and then copy it to whatever projects I want updated with it.

    I also have a 'create project' script that creates new unity projects with all my files layed out and generates the buildscript to be ran that updates it when necessary.

    Mind you when I say "scripts" in this context... I don't mean "unity scripts". I mean just general bash scripts.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    We have common code on a separate SVN repo and use externals to bring it into multiple projects. Not perfect, but has served us well for several years now.
     
  5. Mullan7

    Mullan7

    Joined:
    May 23, 2013
    Posts:
    79
    These all sound like good approaches. I think I'll try out the packages. Thanks!