Search Unity

Personal "framework" to share between Unity projects

Discussion in 'Scripting' started by Kamalen, Aug 31, 2015.

  1. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    Hi,

    We have a serious issue considering stuff we would like to share between projects.

    Simply set, we have a bunch of POCO, unity components and prefabs we would like to use between multiple projects. Contrary to what we would have believed, there seems to be very little on the topic online.

    We have found two methods actually but they seems quite incomplete :
    - DLLs: DLLs cannot allow any prefabs in them, and still needs a manual copy into the project.
    - UnityPackage does not apply any rename or delete of assets to the project. If we have to delete the framework folder at each update, we will spend more time relinking every scene and scripts than actually progressing

    If anyone has any better solution, or if there is a way to make those ones work better, we will be very grateful.
     
    MadJlzz likes this.
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,536
    We have built up a framework as well with our projects here a Jupiter Lighthouse.

    I share a portion of the code base on github actually:
    https://github.com/lordofduct/spacepuppy-unity-framework

    For the code base, we use the dll. I have a folder that I keep as a 'template' that I bring into projects when we start new ones. And a .bat file that allows quick syncing to the template folder if I make any updates to the framework during work on the project.

    The meta files for the dll's are maintained there as well so they copy just fine as well.

    The meta files are actually how a prefab references scripts. So as long as you maintain the meta files in sync with the code files (dll's in this case) you don't have to relink or anything. As long as those prefabs don't reference anything outside of what is maintained in that structure.

    This a bit of leg work that goes with it (I have tons of scripts and bat files that go along with it to assist my syncing process), but it works out in the end. It ain't easy though... I'll say that.
     
    zombiegorilla likes this.
  3. MadJlzz

    MadJlzz

    Joined:
    Jan 24, 2015
    Posts:
    8
    Hello lordofduct,

    I agree with you for the part with the code base. I wondered if dll's would do the job but I trust you if you say so.

    I've checked you repository (which contain lot of great stuff - nice work dude) but I don't see any prefab. So my next question is how does one manage this kind of files ? I mean, what if I want to create a prefab to reuse it in all of our other projects using our framework ?

    Thanks for your quick response.
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,536
    Yeah, I only share a portion of the code base on there, not any of our prefabs.

    Like I said though, you just need to maintain the meta files with the prefabs and dll's. Because the meta files really just reference the scripts that get attached via a 'guid' that is defined in the meta file, when you bring them into a new project, that meta information is carried along with.
     
  5. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    So you say there is an ever running .bat files who copy your framework to any project files, should he detects changes ?
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Would having a version control repo in a specific folder in your assets directory work? You could have the version control for the rest of the project ignore this folder.

    Just thinking out loud, my own frame work is still simple enough that copy paste is practical.
     
    zombiegorilla likes this.
  7. Kamalen

    Kamalen

    Joined:
    Dec 27, 2012
    Posts:
    29
    Never thinked of that. This option looks to be the best to our needs, but will complicate the work of our not-at-all familiar artists with Git.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Give them something like GitHub desktop. Most artists should be able to handle that. Version control doesn't have to be done with the command line.
     
  9. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    At some point I'll go the route that @lordofduct is talking about (dlls), but mostly I do like you, copy/paste. I have a tools project where I keep and work on shared stuff, and manually copy from there.

    As for repo inside another repo, we tried that at work and it caused all kinds of problems. Mostly with conflicting guids. One of our other TAs came up with a pretty elegant solution though...

    We have many support projects for our game (or rather, my last game). All the content has their own projects (characters, buildings, environment, ui, fx, etc...) about a dozen or so, each with its own Git repo. But the all (mostly) need the same shaders, and they have to current for bundling.

    So we created a shaders project. When anyone modifies that project they run a 'commit' script that pushes any changes to that project and records what changes were done (add, mod, deletes). It then sends that info to a python script that copies/deletes those files to all the other projects (not the metas), after running a pull on each. It then opens and closes each project. (This part is so that those projects will update the metas properly for each of those projects). After that the script runs a commit and push on each project. This way each project has the latest shaders.

    It sounds a little convoluted, but it's all automated, and only requires running one editor command. The whole thing usually only takes around a minute or two. (Sometimes a little longer if it hasn't been done in a while).

    So far that is the best way we have found. If there is a better way I would love to know. It works great, but feels a bit clunky. ;)
     
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Seems like the perfect target for an asset store utility...
     
  11. MadJlzz

    MadJlzz

    Joined:
    Jan 24, 2015
    Posts:
    8
    Last edited: Jun 14, 2016
  12. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    Actually I'm amazed no one mentioned symbolic links, it's really easy, put all your shared stuff in a folder, then whenever you want to "import them" into any project all you do is go to the assets folder of the project you want, open a CLI with admin rights (or none, depending on your OS), then create a link that folder, restart unity if required (but usually not). Now all changes you do on that shared folder from anywhere will take effect on all projects immediately.
     
  13. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    That doesn't work out very well. You might be able to pull it off with a file (though you will get a warning), but a folder would be problematic. The meta files (guids/etc) will be different in each project. Switching between projects can result broken links.
     
  14. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    Actually I've pulled it off normally with 2 projects sharing same folder without problems, also you can combine this with partial classes in c# it'll allow you to have same script attached to prefab but different behaviors on each project, true it can be done with inheritance but partials were simpler in my case.
     
  15. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Same. In projects in the past I've also setup symbolically linked directories for many, many shared projects. As long as you're forcing projects to use visible meta files and text serialization it should be just fine to do as long as you don't create recursive links.