Skip to content

Today I learned

How do I make Unity asset GUIDs the same on every machine?

· updated #Unity #Game development

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:

python
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.

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.