Today I learned
How do I make Unity asset GUIDs the same on every machine?
If a .meta never reaches git, or an editor script builds the same material on two machines, Unity gives the asset a random GUID each time and every prefab that pointed at it loses the reference.
Fix: derive the GUID from the asset path. A Unity GUID is 32 hex characters, so an MD5 fits:
import hashlib
def stable_guid(path: str) -> str: # "Assets/Materials/Rock.mat"
return hashlib.md5(("my-project:" + path).encode()).hexdigest()
The catch I found testing it: a file dropped into Assets with a ready .meta keeps that GUID, but AssetDatabase.CreateAsset always assigns a random one, and rewriting it mid-build destroys the object the builder holds. So a script fixes GUIDs after the build, with Unity closed, only for assets whose .meta is not in HEAD yet, and rewrites the old GUID in all text assets. A pre-commit hook runs it in check mode (asset without .meta, orphan .meta, duplicate or random GUID), and an [InitializeOnLoad] editor class runs git config core.hooksPath .githooks so every machine gets the hook.
Hit this when code-built prefabs opened on another machine with missing models and materials. Docs: Unity asset metadata.