2
\$\begingroup\$

In my Unity project each of source code files is accompanied by .meta file

SceneGenerator.cs
SceneGenerator.cs.meta
Scenes
Scenes.meta
SpawnShape
SpawnShape.meta
Stockpile.cs
Stockpile.cs.meta
WaterAreasMaker.cs
WaterAreasMaker.cs.meta
Workshop.cs
Workshop.cs.meta
WorldGrowth.cs
WorldGrowth.cs.meta
(...)

is there some useful info recorded there that should be tracked in a repository?

https://unityatscale.com/unity-meta-file-guide/faq/#should-i-add-unitys-meta-files-to-version-control claims that there are dire consequences for not tracking it, but in my experience just removing all of them results in nothing problematic.

Unity will just (sadly) regenerate them.

What is the use of this .meta file for source code? Is it safe to not track them in repository? If not, then why?

Is it possible to get rid of them somehow?

(I know that my problem is partially caused by having a very unusual way if implementing Unity project. Everything is done by code, no models, code is written in an external editor, with Unity Editor treated only as compiler and runner)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Since the official documentation describes what the meta files do for source files, can you clarify in your question what exactly about this is unclear? \$\endgroup\$
    – user35344
    Nov 10, 2021 at 14:29
  • \$\begingroup\$ @Tyyppi_77 thanks for pointing me there! I posted answer that - I think - describes the situation, though I may be wrong. I was unable to find this docs as I was specifically looking from git/repository/programming side and I only run into CEO marketing setups like one that I linked. \$\endgroup\$ Nov 10, 2021 at 14:35

2 Answers 2

2
\$\begingroup\$

One of the most important things stored by Unity in .meta files are the GUIDs of assets, including script files. These identifiers are used by Unity to uniquely and definitively identify that asset. Any time Unity needs to identify a specific asset (in particular, because that asset is referenced in Unity's editor) then the GUID stored in the .meta file gets used. This is why it is normally crucial to track the .meta files in version control: if you lose the .meta files, then all references to that asset will break.

The reason it doesn't matter in your specific case is that you don't rely on script references within Unity's editor. Since your workflow doesn't involve Unity's editor, there are no references to break.

(related tangent: Meta files were actually introduced to Unity in order to support version control. Previously, in the earliest versions of Unity, the asset GUIDs were stored along with the giant mess of temp library files, resulting in projects that don't play nice with version control.)

\$\endgroup\$
3
  • \$\begingroup\$ > there are no references to break Strictly speaking there is single empty "script attachment" object where initialization of everything fits outside Unity Editor - I guess that renaming it and deleting .meta file would cause problems. \$\endgroup\$ Nov 10, 2021 at 16:06
  • \$\begingroup\$ BTW, is there some way to stop Unity from generating them if I know that in specific case it is pointless? (likely this case is so unusual that Unity is not providing something that would be mostly footgun) \$\endgroup\$ Nov 10, 2021 at 16:07
  • \$\begingroup\$ Yeah there's that. So the upshot is, even if you don't technically need to version the .meta file for every one of your scripts, you probably should just to be safe. \$\endgroup\$
    – jhocking
    Nov 10, 2021 at 16:08
2
\$\begingroup\$

.meta files matter in cases where

  • file was renamed/moved outside Unity
  • file is assigned to asset in Unity (script is attached to something)

https://docs.unity3d.com/530/Documentation/Manual/BehindtheScenes.html appears to indicate that .meta files are utterly useless for script files not referenced directly by Unity objects.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .