A brief discussion on the function of Unity’s Meta files and the text content analysis of prefab and other files

All files in Unity are in text format and the content can be seen.

Meta file format: (different files may have different contents starting from the third line)

fileFormatVersion: 2
guid: 8c37735a974bb7f4a8fa831a31dff02a
PrefabImporter:
  externalObjects: {}
  userData: 
  assetBundleName: 
  assetBundleVariant:

After the file is imported into unity, the meta file will be automatically generated.
The main recorded content of the Meta file is the GUID and file import settings.

1.GUID:
guid: 8c37735a974bb7f4a8fa831a31dff02a is the unique ID in the entire project. It is assigned after importing, and there will be no duplication.
If duplication occurs, a yellow warning will appear:
Test method: Create a new material named m1, and unity will generate the corresponding m1.mat.meta.
Open the path where this file is located, select m1 and its meta in the folder, and copy it.
Then open Unity and wait for automatic import. A yellow warning will appear: Insert image description here
Do not move or delete files outside the Unity engine.
In fact, Unity will reassign the GUID to the wrong meta file imported relatively late (sometimes it will not allocate it, keep the meta file conflict state, and will not warn again, I don't know why). The problems caused by conflicts will be discussed later.

2: Import settings
Test method: After the icon is imported into unity, switch to sprite mode. Commit svn. After modifying MaxSize 32.
You can see that the change size has been modified from 2048 to 32. The red box part is the publishable platform. Can be modified individually.
Insert image description here

The connection relationship between files in Unity:

Test: Now there is a material and a picture, and the picture is hung on the material:
Insert image description here
as shown in the figure, there is an icon37 on the m1 material. Insert image description here
After saving, you can see that m1.mat has been modified. Insert image description here
Comparing the differences can reveal a line of content modification.
- _MainTex:
m_Texture: {fileID: 0}
changed to
- _MainTex:
m_Texture: {fileID: 2800000, guid: 336f4b4eab0aaef4a882d98f5ae39ec0, type: 3}

Open the meta file of icon37 and you will see
Insert image description here
the GUID: 336f4b4eab0aaef4a882d98f5ae39ec0
. You will find that the GUID of the image is the same as the GUID of the modified content in the material file.
Therefore, the dependency reference association between files in Unity is carried out using GUID.
If a meta file conflict occurs, the GUID recorded in the file may not be the originally selected file. File loss will occur.

Test:
guid: 336f4b4eab0aaef4a882d98f5ae39ec1
I changed the last digit of the picture GUID from 0 to 1.
After entering unity, I found that
Insert image description here
the picture on the material was lost.
The same applies to various file associations in Unity:
I hung a script on a GameObject, and modified the script's meta file GUID to
Insert image description here
Insert image description here
Insert image description here
report different error forms. If the word "missing" appears, there is basically something wrong with the GUID.

Unity file saving

All files in Unity are text files,
so if I modify the coordinates of an object, it will actually be reflected in the file content.
Insert image description here
I changed the coordinates of a prefab from 000 to 9.87
Insert image description here
to compare the differences. You can see that the coordinates have been modified. You can see that the modified field name is m_LocalPosition.
Its parent node is Transform, which corresponds to the position of the Transform component on the panel in Unity.

Parameters including custom scripts will be displayed on the panel.
I mounted a script to the node and checked the differences: Insert image description here
Insert image description here
I found 2 modifications.
component: {fileID: -2879555396794527001} shows that a new reference GUID is added to this object, which is this string of 287955…. What is specifically quoted is explained in the following paragraph:

The most important lines:

Line 83 — !u!114 &-2879555396794527001
— !u!114 is the unique ID in this text
-2879555396794527001 Mark the above quote

Line 84 MonoBehaviour:
Indicates that this reference is a custom script. The types of custom scripts in unity are all MonoBehaviour

Line 92 m_Script: {fileID: 11500000, guid: 5779c70bde44e2542abf571ef9a2b611, type: 3}
GUID is here. In addition to ensuring the uniqueness of the file and determining the association between files, the GUID will also mark the directory where the script is located
(so as mentioned above Yes, warning: Tip, do not move or delete files outside the unity engine. If you move the file path inside unity, unity will re-record the directory where the GUID is located, and the GUID will not change)

Line 94: m_EditorClassIdentifier:
Starting from this line, they are all parameters on this custom script. For example, my script exposes a slot named a,
Insert image description here
then line 95 in the text will also reflect a: 0
i Make modifications in unity
Insert image description here

If the A value is changed to 567,
Insert image description here
you can see that the text has also been modified.

Summary:
1. A large number of modifications, in order to save time, the text content can be ignored.
However, before submitting small modifications or parameter modifications to SVN, you should compare the differences between the current versions to see if you have made any redundant operations or misoperations. Uploading incorrect operations will cause various problems, and re-debugging will be time-consuming and labor-intensive.
2. Why do you need to understand the unity file saving format and principle:
You think you have done 12345 things in the engine, but this operation is really effective? Does the engine really know? The saving of files (serialization and deserialization) is the real reflection of the operation itself.


The above operations are performed using SVN+Beyond Compare.
If you don’t understand the operation, you can chat privately, leave a message, or contact us via QQ.

Programming is endless.
Everyone is welcome to communicate. If there is anything unclear or wrong, you can also chat with me privately.
My QQ 334524067 God-like Didi

Guess you like

Origin blog.csdn.net/qq_37776196/article/details/116006274