Your techniques to share code between projects?

How do you distribute code between projects? We have multiple projects with multiple programmers. These are some of the problems we’ve been having.

  • How to ensure bug fixes to a package in one project make it to a second project?
  • How to distribute internal packages?
  • How to handle dependencies? Eg: Our IAP package should require our Analytics package to be installed.

We are talking about setting up an internal NuGet server to distribute DLLs via NuGet for Unity. It seems the Package Manager will be the way to do it in the future, but it does not seem to be ready for custom packages yet. We attempted to use git submodules, but having loose cs files caused code to diverge pretty quickly.

Or is there some other solution other people are using?

1 Like

I have found that bundling your own code into DLLs only serves to slow down your workflow. I base this on several years of experience dealing with other teams well-intentioned packaging mishaps. With games, it is almost always useful to reach into library code, make a temporary tweak to isolate a problem, and then revert it. With DLLs this is impossible, making workflow harder and more brittle.

I prefer to share source code at the C# level. That way I can reach into libraries trivially and inject whatever instrumentation I need to in order to track down the issues I am having. You know this will be necessary, so denying it is just setting your team up for extra unnecessary work trying to track down bugs.

Here’s some of the observations I’ve had with source code-sharing methods in Unity3D. “Library” refers to the shared code, “client” refers to the game client using the code.

METHOD 1: Clone the code (from library repo into client code repo)

PROS:

  • pros: all changes to your code are recorded clearly in the client source control DAG, allowing easy forensics with little confusion, no other repositories to study.
  • the client can fork the code if it needs to (i.e., make local changes to library code, perhaps to later “upflow” to the library if warranted)
  • good version control discipline will help preserve functionality when you do drop newer versions of the library code into the client code.

CONS:

  • duplication of code
  • easy to lose customizations that you actually wanted to “upflow” from client code to the library. This just requires tracking and extra discipline.

METHOD 2: Using source control submodules:

PROS:

  • supported and enforced by version control
  • even works for Editor/ and Resources/ and other “special” subfolders in Unity3D
  • gets even better if you use good C# namespacing

CONS:

  • depending on your branch strategy (git flow, etc.) you have to keep both primary repo and all subrepos “merged in sync” with your branching strategy. This is VERY tricky to visualize and get right, despite it appearing simple on the surface. With git-flow a simple merge from rel → develop is actually multiple separate merges, and the chances of errors skyrocket.

METHOD 3: using symbolic links from client to shared code library

PROS:

  • extremely slick and fast iteration for any given team member

CONS:

  • scales poorly to many team members
  • it can be mysterious why something stopped working when a library file changed and the client repository doesn’t reflect it
  • every developer installation requires symlinks to be setup (either Win32 or MacOSX), making it impossible to “clone the repo and go”

Personally I favor method #1 above using the “Clone the code” method, along with strategic upflow and downflow of shared code. I generally try to keep all the library code in a single folder in a reference “library test project,” and then copy just that directory down to client projects. This is how I manage my datasacks repo, which I share between a lot of my games.

EDIT from June 2021: I favor #1 only up until a certain scale of project size. For most commercial projects, approach #2 of properly configured submodules is a clear winner, and scales very nicely to CI/CD and builds and even for inter-team library shares.

Again though, I would NEVER reach for DLLs. It’s been a complete disaster every time I’ve seen it tried. It gives you zero benefit and nothing but headaches for the engineers. And if you think “Oh my IAP library is final,” you are most likely incorrect. It will have bugs, there will be changes to its requirements. No software is final. Software is soft. And you already know that Apple and Google WILL change their IAP.

And as for dependencies, if library X needs library Y, either put them both in your project, or make one a sub-library of the other.

I also would NOT reach for NuGet. I have wasted far more time tracking down weird dependency problems than I’ve saved by Nuget’s automatic dependency handling.

23 Likes
Id like to restructure my entire project, how to?
Same Project, Same Version, Two different computers = Errors
Unity is now at 70 minutes to load, about 25% of the way done
Unity Version Control don't work
A little story about using backup project folder
Unity Project problems, running same project on second PC
Gray Screen on Build
Unity doesn't have a backup solution, be careful you should have your own!
Code isn't working anymore
System numeric Vector
Unity ruined my last 48 hours Part-2 Cruel Library
Collab won't let me add a third seat
[Suggestion] - Upgrade Version Control Icons With Higher Resolution
Unity Version Control - switch workspace
very weird error
Unity crashed and now my project is having problems.
Issues with Terrain Asset files and general git issues.
Removing assembly definitions from project
Just lost 4 hours of grueling revamping because this crash-prone engine doesn't have Auto SAVE.
How to get rid of grey box??
My player is not moving at all
what is wrong with my PlasticSCM????
TextMesh Pro completely broken after compressing project as unity package — Unity 6
Unity duplicates assets back to root folder again after moving them
Can't Make Character Move Up Smoothly While Following Path
Moving from Unity 2020.3.3f1 to 2021.3.11f1 Android build problems.
How can I upload more than 100 files from Unity to Github?
Unity is not opening my project
Collab bug
Cannot open Android project and cannot switch other projects to Android Build.
Debugging with external Dll
The name 'Mouse' does not exist in the current context
My game lit itself, can't figure out what happened.
I can't find the collab button
Git command prompt opens frantically in Editor
Unitty exe to files
Unity highly unstable/unusable on macOS
Project transfer
Unity projects bigger on external SSD
Project behaving strangely after having pulled from github
How to deactive unused scripts without having to delete them?
Splitting up a terrain object into different regions
Place an array of non-tile, square 2D sprites in a flush grid to set up game
Everything... broken...
How to fix a scene that was migrated from Mac to PC?
Failure while building - have built project dozens of times and haven't changed settings
PC soft locked, now my build has reverted to an earlier state.
AddForce() suddenly stopped working
i don't have the collab button.
Project broken after moving it to a new pc
Can't open scene after downgrading unity version
How to resolve The type or namespace name 'bool3x3' could not be found error
Project crashing on startup
Work on one project across multiple systems?
How to share source code
Build broke my scene? HELP APPRECIATED
Unity Android App back to the Projekt
how to use cloud.unity
Is it possible to use these files?
Error - These items are exclusively checkd out by: MYSELF 2
My unity game in editor is deleted, but the files are located in there
Connect to the server (Plastic SCM) page keeps coming out
Need Objects to destroy
How to add my project to github ? Can't find Version Control > Visible Meta Files
Working between both of my PCs.
Pls help me pink terrain is driving me crazy
AppController.mm not found
Releasing my first game! Proper release workflow?
Importing an existing unity project into github, how do I do it?
How To Properly Backup Unity Engine Project(Not Using Git)?
Reverse engineering Unity game from .exe file and _Data folder
2019.4.28 crashes on Mac OS Big Sur on Start-up (Stack-trace included) - InitializeAssetDatabaseV2?
Track Changes stopped working on my Unity project in Visual Studio 2022
Working with several people on one project
Compile errors, but no errors reported, nor in editor
Why is there no download button?
Issue with my ProBuilder Mesh
new to JSON - one line in JSON = one object?
Sprite Atlas, Stack over flow
Came back to project after 3 weeks break, have 280 HDRP errors
Multiple precompiled assemblies?
Blue plus with my prefab icon
Upgrading an old project from Unity 5.x to Unity 202x ?
renaming scenes
Uninstalling an old version of unity removed projects
Prefab changes not loading from Git Pull
Separate project modules
Corrupted File Removed From Collab History: Lesson Learned
Corrupted / Missing Unity Files on Project Update and Creation
Moving project files
Self destruction (872297)
Phantom Error
Light settings bug in HDRP
On Editor update: Build settings -> Texture compression gets reseted on the first import
Game Window Gone Black on Play
Need help with abandoned Asset. No support. Need help Building DLL from Source.
Scene broken after PC Shut down
Need advice on setting up a new git
DontDestroyOnLoad - Prefabs Data Persistence
[BUG] Plastic SCM Deleting Addressables & Removing Files.
Spinner Physics Issue
UNITY JUST WRECKED MY PROJECT?!?!?!
Which files are okay to just copy paste from one project to another?
How to delete historical uploads in a collab project
My project is hosed
Removed project from list, With no backup.
hey i cant seem to transfer my unity file
New computer transfer issues
Upgrading to new Unity too often breaks projects
back to older version and then got errors
Unity not saving scenes or project. Lost everything twice.
The type or namespace name could not be found (922928)
Which version control for small Unity projects?
Help with unity.
New Folders are private.
Lost keystore. Unable to upload app with new keystore. Help Needed !!
Plastic Cloud Not Loading? (912410)
List obsolete APIs without updating?
huge project size because of library folder
How do you have multiple people working on the same game?
When opening a script from the editor in visual studio should I recover or not the file ?
Project Isn't Working 100% After Deleting Library Folder
Unity Closing When I Open A Project
"The script is an editor script" error when script is not an editor script
"Help corrupt Terrain from Git: ""Unknown error occurred while loading 'Assets/Terrain/Terrain_0_5..""" (803873)
Would there be any problems repeatedly changing a project from Windows to Mac and vice versa?
Plastic scm offline?
How can I save and load progress bar?
Best way to store fixed game configuration data
PlasticSCM group work not showing
Plastic SCM Error "the remote host closed the socket."
Where will Scripting Define Symbols be saved?
After the last update I can't build the game
In Collaborate, can we diff check files?
Download unity 4.6.5f1
Manually upgrade to C# 8
How can use SourceTree as local
Cannot Use Same Unity Project Between Desktop & Laptop
Editor not opening project! I cannot lose this project!
Renaming Scripts in 2023.1.6f1
Turning a script package into a DLL without breaking everything
importing unity made asset messed up rigidbodies.
Problems with Unity Builds on Mac and Google Drive / Dropbox
My Scripting Define Symbols are gone, how to regenerate them?
Build fails when project is copied to a different directory or computer and compiled
Unity Cinemachine Stopped Working; Doesn't look at the Look At Target
Unable to restore to last job I saved in cloud scm (873944)
Unable to open/view remote project from a different organisation in Unity Hub
I lost all of my scene assets, after scene reload.
Prefab lost all assignments
Unity Editor crashes when loading scene
Complicated Error After Installing Assets!
PSB issue: How to export Sprites from Unity (and update Sprite-References) ?
Gradle build failed (908038)
Collaborate service giving error.
999+ errors, all of them are my scripts that got messed up.
How to preserve id in dll of package imported from git?
How to preserve id in dll of package imported from git?
Could not find a part of the path (849661)
Is there simple trick to revert temporary changes
Lost my work
Deleted a unity version control repository and can't change a unity project to the new repository
Unity 2019.4.23f1 Broke Prefabs and Project - NullReferenceException, ArgumentNullException
Scene Management for platformer/metroidvania style game
How to clean up project files to reduce size before backup?
Which Android build folders can be omitted from a Project Backup?
Some gameObject lost!
Hdd Died is it possible to salvage anything from a apk build file?
Need help fixing build issues after update from 2021->2022
Opening remote project with plastic scm opens an empty project
Script compiles but the MonoBehaviour class isn't detected until reimported
i accedently deleted the gamemanager script
Editting multiple prefabs in editor via script
Collaboration not working
Should the fields of a 2D RPG be divided into scenes?
Hundreds of "New Game Object" in scene...
Lost my project due to collab "restore"
How can I retrieve a scene I was working on if it is not among the assets?
I'm in shaded mode, but it only shows me black and white spots
Is it possible for project file corruptions to propagate through revisions without detection?
Error importing texture after upgrading to Unity 2023.1.2f1
unity collab delete my project
Library folder goes way too big!
Unity CS2012: Cannot open 'Assembly-CSharp.dll' for writing
Game doesn't run
Unity destroyed the content of one of my project's folder ?
Can't open project on 2 PC's at the same time on network drive?
Unity Engine Treats warnnings as Errors
Recovering Lost Unity Projects Using Unity Dashboard?
UI disortion after project update
What folders should I backup
Is it right to delete all "Unity" folders after testing an asset store asset to restore to default?
How do I update used assets in a large project?
Cant figure out how to collab on a Unity project. (please help)
Unity Crashing on opening a specific scene .
Unity gets stuck while building 64-bit version for the Play Store
Unity.Plastic SCM.Editor.Plastic Plugin error
i want to save my project from build
How to save everything? I can't reliably save things.
the associated script can not be loaded
Best solution for collaborating with multiple team members (909762)
Painless conversion from MonoBehaviour to ScriptableObject?
I am trying to open a remote project using PlasticSCM, but I get a error
Unity 2019.4.29f1 has blank collab history window
The referenced script (Unknown) on this Behaviour is missing! (842708)
How to retreive a deleted animation from an object?
How to delete Unity Plastic SCM cloud repositories?
Scenes no longer show up in the indexed search window
Updating to 2020.2.4f1 messed up all my prefabs!
How to duplicate 2D projects
I want to continue my work on my game on my iMac
Can't upload to Google Play due to non compliant SDK com.unity3d.ads:unity-ads
How can I work on a project with other people?
WebGL build size optimization
Please tell me there is an easy/automatic way to revert my WHOLE project back to SRP from URP?
My PSD importer stopped working?
Unity foot folder will not copy/paste for a backup
Backup broke my game- Anyone see a fix?
Need help (Beginner)
Build game screne goes black
Missing types referenced from component UniversalRenderPipelineGlobalSettings on game object UniversalRenderPipelineGlobalSettings
BuildAssetBundleExplicitAssetNames error: Moving file failed
Upgraded project from 2020 Unity to 2021 Unity and now nothing works.
moving from plastic scm to version control
Unity Stuck On ProjectBrowser.Repaint After Opening Without Internet Connection Using PlasticSCM
Can't commit Unity because of large file
What happens with serialization when unity restarts?
Unity + Plastic + Odd Situation help
2 Compile Errors appeared that I cant understand how to solve appeared randomly
"If I share a Unity project on Github, will it work on a new Unity installation without prior setup?" (848583)
when I load specific scene I get editor crash
Updated editor, now project is all messed up
Build Failure org.xml.sax.SAXParseException
What version of Unity should I be using? What version of Android? I need to remove Unity splash screen
Scripts missing after refactoring name in many locations -- how to fix?
Error with Collab
Everything gone in scene
Creating new Namespace within C#, not sure why
Is there any way to build only the modified parts each time, as a separate SO library for updates?
Package Cache error
Creating a dll of a package changes file id's
Error message when new project is started. Clews?
Minigame 'spawn'
Project Artifact Has No .META File
Scripting define symbols empty
Issues with Unity Version Control
Collaboration error
How to keep same HTML and CSS file between different builds
Creating a grid system in a 3D world
Can I open a previously saved version
All gone
What is Recovery GameObject
PasticSCM randomly injecting code into my project and other errors during Build - 2022.3.1
Blitter is already initilaized exception after installing HDRP on older project, upgraded to 2022.3
Latest Updates Made Game Unplayable
I need a hassle free "time machine" style backup for my ongoing developing projects
Unity and Git/GitHub not playing nice
Slow Loading Time - Scene Loading Async
Unity Error CS0246 NuGet Package MQTT not found, despite installed with no Visual Studio Errors
How do I go back to past edits without collab feature?
redownload from play.unity.com
My progress on new project is gone, is it my fault?
Error Build
On - line editor
Prefabs randomly change on their own
Game texts: How do you manage yours?
About projects backup, team workflow and github
6.2 Beta fails to roll back test framework version
Move Project to M2 Mac, how?
What's a good way to share code between Unity projects?
Collaborate sync problems - "Recovery gameobject" [SOLVED]
All my mesh folder content is gone
Having projects on cloud and accessing them using different computers?
Is there any way to create a script from an editor window?
Transfer scene from one project to another
Version Control Error
Bird flying backwards in Angry Birds Like Game Tutorial (Terrible Tweeters YouTube Tutorial)
Exclude scripts from build
What's wrong with UI Toolkit?
Unknow error occurred while loading scene
Partnership working?
Error message in version control
Should I continue work on a project in 2019.3.9f1, or should I try to update
Scene crashing after importing a package
Your preferred package management for personal tools and content?
Why do all my scripts keep detaching when I copy my game files?
Scene's Path Lost
How to ship my Unity devtools package as DLLs, without prefabs breaking
Is there a way to recover permanently deleted game files?
Best practices for maintaining a Unity package between multiple developers?
Seems i should've exported all ProBuilder meshes, all except 1 mesh are lost in the 1st scene
Screen safe area issues in Unity 2018 LTS
How can I (Re) attach scripts to addressables between projects?
Transfer old 2D project from laptop to new PC (without USB stick)
Project script unable to function overnight
Editor crashes loading scene
How to properly integrate one project into another?
GameObject script references broken across project
Git corrupted my Unity project I think. HELP!
Rigidbody physics not working
[Tutorial] Setup Git in a Unity project
Please put the branch name in the delete branch box
Version Control takes way too long to find stuff to check in
Where do I start with version control?
Unity SwitchOnInteger compile error
Best way to package a script that can be used by multiple libraries?
Unity editor issue in animator layer
File cant be read
Combining Multiple Projects into one Project
URP pink textures Only in editor, different results on different PC
Unity Version Control - "The file unitygui.conf contains errors"
Black screen in VR headset when running app
How to restore a scene to a former save?
Visual Studio or Visual Studio Code
Player has suddenly started veering along X axis
Why AI copilot modifies scripts whitout permission?
Unity Scene Files Disappeared After Using Git and GitHub
How to make projects with friends?
GIT conflict markers in .meta files (usually guid conflicts) [SourceTree]
Best practice for updating your own packages
How to Recreate this Electromagnetic Effect?
Game compilation to APK and .aab, never finishes
Unity playmode no longer works in Quest 3 headset
Can't Open Project Via Unity Hub
What is the best way to upgrade a project from Unity 2017.4.40 up to Unity 6?

In short: We use dlls in the Unity projects, but each dev has access to the (source controlled) projects of the dll and can change/build the dll code when needed.

We use separate (Visual Studio / C#) projects for “common code” for example let’s say a “Example” project, they are source controlled and independent from any Unity project. If a Unity (Game) project wants to use the “Example” code we just get the newest “Example”.dll and copy it to the Unity project.

If you want to debug code in there, then you can still debug “into” the dll code as long as put the needed debug files into the Unity folders (same folder where you put the .dll itself).

Now the workflow if you actually want to change the code (maybe you found a bug or you want to add a new feature) in that case we get actual (latest) source code for the “Example” (Visual Studio) project and then change the (debug) build output path to the current Unity project folder location (This part is optional, but otherwise you would have to copy/paste the newest .dll after each change/build from the build folder to your Unity project folder). Now if we change the code and build the project it will overwrite the “Example”.dll inside your current Unity project where you want to test the code changes.

Then you can either checkin the changes to the source control or revert it if you don’t need the changes. (If you fixed a bug and want to fix the bug in your other projects as well, then they would have to replace their current “Example”.dll with the newer “Example”.dll which contains the bug fix)
→ This depends on your company size if you have many teams working on different project at the same time and they all modify the code of the “Example” project, then you might need different branches etc, but that’s a different topic and in that case your company would most likely already have a strategy to share code

The downside with this method is that you have to rebuild the “Example”.dll after you change the code and overwrite the “old” dll in your Unity project (see comment above), but in my opinion it’s still better then duplicating the whole code into each Unity project

There is one important part about this: While working on a new Unity project we build the dlls in debug mode, so don’t forget to rebuild the dlls in release mode before shipping the game or running performance tests :wink:

In addition to the 3 methods from @Kurt-Dekker , we utilize two different methods:

METHOD 4: UPM git packages/custom UPM server (this was not possible in 2018)
Good for modular, project independent code (e.g. custom httpclient wrapper for custom backend)

PROS:

  • all the advantages of UPM (easy distribution, versioning, dependencies)
  • code in separate folder (Packages)

CONS:

  • not mutable, every change must be done in the original repo

METHOD 5: Branching + git worktrees
Good for projects with common codebase with only a few variations (e.g. game reskins, AB tests etc.). This combo is better than forking - less space on disk, faster manipulation, faster setup. Common codebase is master branch, variations have branches of their own and with worktrees you have all the advantages of separate repos.

PROS:

  • all in one repo
  • fast sharing and distribution of code (git merge strategy is great)
  • quick setup (one repo)
  • simple serialized data and assets other than code (graphic, audio…) may vary greatly.
  • once the differences are too big, you can fork the branch to separate repo.

CONS:

  • really only useful when the common codebase has only a few variations/additions, otherwise can get complicated. This is also true for complicated serialized objects like scenes and prefabs, merging can become overwhelming even with git. You can solve this, by having less in common stuff in master branch, but than you have more work to implement changes on each separate branch - this goes against this workflow.

There is another way with git, similar to @Kurt-Dekker METHOD 2:

METHOD 6: git subtrees

I have used submodules but never subtrees, so if anybody has experience I would like to read about it.

3 Likes

Sharing some success/failures sharing files between projects on the one machine.

My problem: I am trying to do animation (a hobby project) with Unity using Cinemachine, Timeline, Sequences, etc. I also purchase assets from the asset store for different locations. I then have a set of characters (created in VRoid Studio) and props (bags, hats, etc) that I want to use in different locations (characters and props are not limited to a single location). Unity staff recommended I start a new project per location to avoid the project getting too big (it got crazy slow after a while). That means I need a “common” project and 10 to 20 “location projects”.

I have:

  • Versions of Unity packages (like Cinemachine, Timeline, and Sequences) that must be kept in sync across projects
  • Assets from the asset store that must be kept in sync across projects
  • Models and scripts I create that must be kept in sync across projects.

In my Common project I created a custom package under Packages/MyCommonStuff with a package.json file that listed the Unity modules I depend on and their version numbers. Other projects I used “Add Package From Disk” to point to the package.json file directly in the “common” project. That works. Changes made reflect automatically across all projects. (It can be hard to work out the package names to use in the package.json file as the docs only list the human friendly names.)

I tried moving assets downloaded from the asset store into the Assets/ directory into the Package/MyCommonStuff directory as well. There were problems getting things to compile, separation of Editor vs Runtime vs Test (separation wanted by custom packages), etc. This was a pain as asset store purchased were not designed for this 3-way split into different directories. And then updates from the asset store were also a pain as new files did not go into the package directory so I had to keep rearranging the files. So I gave up on this and wrote a script to create symlinks for Assets/ for around 20 asset directories that are common to all projects.

I also created a Assets/_COMMON directory for my scripts and models to be shared across projects (the characters and their props). Again, I used a symlink as putting this in the package directory with dependencies on the asset directory was not going that well (and is logically weird too).

Not very elegant using symlinks, but it is working so far, guaranteeing all projects are in sync without having to convert unity asset store assets into the unity custom package format (and redoing the work for asset store updates). I would love to hear a better solution, but asset store purchase that are not packages and getting them updated throws a bit of a wrench in the mix, especially as my assets (the characters) depend on the non-package format asset store purchases.

2 Likes

I’m 2 years too late, but wanted to say that I second this :arrow_up::arrow_up: specially method #2. I’ve been using it with Fork and it’s as easy as double-clicking on the submodule icon to open the submodule repo panel, and it’s just like normal repo, you can do all the branching etc right there and ctrl+shift+enter → push to cloud!

edit: users who don’t use Fork can also very easily use submodules in terminal by cding into the submodule directory and use normal git commands there.

3 Likes

As for method #2, which is what I wanted to go for… how do you deal with Unity’s .meta files?

In my specific use case I’ve written an editor extension and now want to add in a bitmap tileset loader and a custom level map importer/exporter. Both are standalone projects with no connectoin to Unity at all.

To my understanding, Unity would clog all the submodule folders with its .meta files, giving me a permanent delta to the original master branches, unless I push to the standalone projects. Branching/forking should solve the issue with the permanent delta, but still I’d have Unity specific modifications in the external repos - which I ideally do not want.

Going the DLL way seems appropriate for this specific use case at first glance, however I dislike it for the reasons stated above - and because the projects were built with different Visual Studio and C# versions. Dropping such DLLs into Unity without rebuilding for the target version just feels like a horrible approach.

Any experience in how to takle this?

Thanks for your insights.

My preference is the git packages, you have records then of which version it was, etc.

1 Like

Since my extensions don’t use any Unity specifics, I have decided to simply gitignore .meta files in the submodule as a first step.
Unity will happily regenerate them whenever needed.

For git packages it feels a tad bit early. None of these projects have left the “exploration chaos” phase yet :slight_smile:

Edit: rephrased post to make clear ignoring of .meta is done in submodule only.

Ok but ignoring all meta files will lead to issues. If you go to a new machine or just clone that repo to a new folder all the links of references will be broken

Why? Unity will regenerate the meta files and git won’t care. I have no customization specific to Unity (which would land in .meta) for these subprojects.

The references in .gitmodules are to GitHub, not local.

edit: Ah, you mean I have to update the submodules manually after clone. Ok, valid point. Not a breaking one for now, tho.

Yeah I don’t understand why this even remotely matters but if it works for you that’s great. I had thought they were necessary but then I never bothered to look since as far as I’m able to determine they don’t have an impact on the version control. Granted I’m on a more powerful computer than most people so they could be and I’ve not noticed.

1 Like

I’d say this in regards to the .meta files… if you need to also share assets between projects you’re going to want to keep them.

For example here’s one of my packages:

This package is for input (written before the new input system from Unity, and was my way of dealing with the jankiness of the legacy input system).

In it I have ScriptableObjects that I can define a input layout and apply them to the global input system. I also have a build pipeline that allows me to define an input layout on a per build configuration:


note the ‘Input Settings’ towards the bottom.

Here’s the thing as you can see in the package at the top of this post I have a bunch of predefined input layouts all labeled “InputSettings_…”. Since these are assets that are instances of my ‘InputSettings’ SO… well they’re associated via guid. And that guid is in the meta file.

If I were to drag this package into a new project without the meta files and allowed Unity to auto-regen all the meta files. My InputSettings_… would all break. Because unity doesn’t know what script is associated with that asset. Since the meta file is how that is determined.

…

So point is, you want the meta files if you want to distribute assets and not just scripts.

Thing is from a git perspective… it’s not costly. The meta files don’t change a lot. This is all they basically are:

fileFormatVersion: 2
guid: 8a589d1624987684f9c15a618e5fd5ab
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant:

The guid should never change, and those other properties only change if well… you change that about them (which isn’t common). So it’s a one time commit of all of 250 or some-odd bytes? If this is clogging up git in some manner… y’all must be using git in way different ways than I have been for years now.

3 Likes

why not add a “*.meta” to the .gitignore of the submodule? Seems like the perfect solution here

1 Like

That is exactly what I did - guess I failed explaining that :smile:


For Unity related code of course .meta does matter. Just thinking of script execution order… but that was not the use case I described above - so in short: Don’t blindly ignore .meta, unless you know what you do.

That submodule I was referring to is plain C# which I happen to use in Unity - and therefore don’t want Unity specific files like .meta in it. It won’t have any serialized data, no execution order and the like - .meta will be “empty” for this submodule and therefore can be regenerated by Unity on the fly without loss.


After some time working with this setup I can say I’m very happy with it. Since the submodules change less frequently than the main project with its Unity files, that extra effort for updating the submodule references comes at a small cost only.

Not to negate your meta file statement at all. Totally agree with your “don’t blindly ignore meta unless you know what you’re doing” sentiment.

With that said, I much prefer using the ‘DefaultExecutionOrder’ attribute over defining the execution order through the inspector (which is what gets put in the meta file). Especially when dealing with my packages.

It’s technically undocumented… or limited documented. I don’t know… it’s one of those weird random things that the unity api docs don’t have a lot of info on. But it works, and I love it.

Here’s a thread discussing it from a few years back.
https://discussions.unity.com/t/701051

Side note: I highly dislike taking care of script execution order by inspector since it makes debugging weird issues a pain - it just served as an example