What is Unity GUID — How to Get & Change GUID?
Today we’ll figure out what Unity GUID is, and why it can be useful to you when developing games or assets for the Unity Asset Store.
Contents
What is Unity GUID?
Unity GUID is a Globally Unique Identifier for the asset.
Scenes, Prefabs, and other Unity files (assets) reference to Asset GUIDs to uniquely identify files within a single project and between different projects (also, with help of code GUID can be used for cross-scene referencing for Game Objects).
How to Get GUID?
GUID is generated by Unity app automatically when you:
- import a new file into Unity Project with or without the help of Unity app;
- duplicate the file (new GUID for the duplicated file).
GUID is originally written in .meta file of targeted file (guid: 8c9c1e4a88e724a60a9ac0b0bb6a52c3).
Previously defined Asset GUID with .meta file is always next to the targeted file when you:
- export a package from Unity,
- import files to project with .unitypackage file or from Asset Store.
You can Get GUID by open .meta file in any text editor like Sublime Text or Notepad++.
Why change Unity GUID?
Under normal conditions, you do not need to change Unity GUID. This is necessary when you are working with several projects and the files in these projects are being overlapped.
For some reason, the same file in different projects can have different GUIDs. In this situation, these are different files for Unity. When these same files (along with related files) with different GUIDs occur in the same (or new) project, there may be problems. In this case, you need to bring the same files to a single GUID. This is relevant when you are dealing with modularity.
Or, on the contrary, you may want to intentionally change the GUIDs for a file or group of files. It is relevant when you are making a new project (or a new file) based on an existing one (with help of copy-paste the folder of the project). At the same time, you change the files in the new project and want to identify them in different ways for further usage.
How to change GUID?
Manual Mode
Example (Generate GUID):
- guid: 8c9c1e4a88e724a60a9ac0b0bb6a52c3 — original
- guid: 8c9c1e4a88e724a60a9ac0b0bb6ababa — modified in the end
If you need to change GUID for one file without related files, you can do it manually with help of changing some digits and letters in the .meta file of targeted file. Use only those characters that are already here.
Auto Mode with “GUID Regenerator” tool
If you need to change GUIDs for many files with related files, you can do it with help of “GUID Regenerator” tool.
“GUID Regenerator” is a tool for creating new Asset GUIDs for existing files inside Unity Project. You can find it in a package of Book for Asset Publishers.
Use “Menu > Window > Makaka Games > Regenerate GUIDs for assets in specific folder”.
Cross-scene referencing for Game Objects using GUID
There is opportunity to use next system: special component for giving Game Object a GUID and a class to create references to objects in any Scene by GUID. Get with GitHub.
Read more info on Unity Blogs: “Best Practices: GUID based references”.
How to Create Unity Assets?
This article is a part of my book (docs) in which I’ve systemized the accumulated knowledge and experience concerning the business in Unity Asset Store.
For Unity Publishers. By Unity Publisher.