Skip to content

Commit 9c86668

Browse files
Rename OldTypeHash, which is a confusing name
Also update comment based on research into exactly what this is.
1 parent 9eee524 commit 9c86668

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

Analyzer.Tests/FileDetectionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ public void TryParseMetadata_PlayerDataLevel0_ReturnsExpectedValues()
232232
{
233233
Assert.IsTrue(entry.InlineTypeTree,
234234
$"InlineTypeTree should be true (persistentTypeID={entry.PersistentTypeID})");
235-
Assert.IsFalse(entry.OldTypeHash.IsZero,
236-
$"OldTypeHash should not be zero (persistentTypeID={entry.PersistentTypeID})");
235+
Assert.IsFalse(entry.TypeTreeStructureHash.IsZero,
236+
$"TypeTreeStructureHash should not be zero (persistentTypeID={entry.PersistentTypeID})");
237237
Assert.IsTrue(entry.TypeTreeContentHash.IsZero,
238238
$"TypeTreeContentHash should be zero for version < 23 (persistentTypeID={entry.PersistentTypeID})");
239239
Assert.Greater(entry.TypeTreeSerializedSize, 0u,
@@ -288,8 +288,8 @@ public void TryParseMetadata_PlayerNoTypeTreeLevel1_ReturnsExpectedValues()
288288
{
289289
Assert.Greater(entry.PersistentTypeID, 0,
290290
$"PersistentTypeID should be positive (got {entry.PersistentTypeID})");
291-
Assert.IsFalse(entry.OldTypeHash.IsZero,
292-
$"OldTypeHash should not be zero (persistentTypeID={entry.PersistentTypeID})");
291+
Assert.IsFalse(entry.TypeTreeStructureHash.IsZero,
292+
$"TypeTreeStructureHash should not be zero (persistentTypeID={entry.PersistentTypeID})");
293293
Assert.IsFalse(entry.InlineTypeTree,
294294
$"InlineTypeTree should be false when EnableTypeTree=false (persistentTypeID={entry.PersistentTypeID})");
295295
Assert.IsTrue(entry.TypeTreeContentHash.IsZero,

Analyzer/Util/SerializedFileDetector.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,26 @@ public class TypeTreeInfo
7070
public UnityHash128 ScriptID { get; set; }
7171

7272
/// <summary>
73-
/// Hash of the TypeTree content as originally written into the file.
73+
/// Hash of the TypeTree structure (field names, types, byte sizes, alignment flags),
74+
/// computed via MD4 over the node graph. Used to detect type schema changes between
75+
/// the version stored in the file and the current runtime type, and to deduplicate
76+
/// type entries when writing serialized files. Sometimes referred to as the "OldTypeHash"
77+
/// because it refers to the type at the time it was serialized, which might be older than
78+
/// the current type.
7479
/// Used for compatibility checking at load time.
7580
/// </summary>
76-
public UnityHash128 OldTypeHash { get; set; }
81+
public UnityHash128 TypeTreeStructureHash { get; set; }
7782

7883
// -----------------------------------------------------------------------
7984
// TypeTree inline/extracted data (only when EnableTypeTree = true)
8085
// -----------------------------------------------------------------------
8186

8287
/// <summary>
83-
/// XXH3 content hash of the TypeTree blob. Stored explicitly in the metadata for
88+
/// XXH3 content hash of the TypeTree blob, e.g. hash of the raw binary encoding
89+
/// of the TypeTree definition. Stored explicitly in the metadata for
8490
/// version >= 23 (kExtractedTypeTreeSupport). IsZero == true indicates this field
8591
/// was not present in the metadata (version < 23 or no inline TypeTree).
92+
/// This is used for TypeTree deduplication and caching.
8693
/// </summary>
8794
public UnityHash128 TypeTreeContentHash { get; set; }
8895

@@ -751,7 +758,7 @@ private static TypeTreeInfo ReadTypeEntry(BinaryReader reader, uint version, boo
751758
info.ScriptID = BinaryFileHelper.ReadHash128(reader, swap);
752759

753760
// oldTypeHash: always present. Hash of the TypeTree content as originally written.
754-
info.OldTypeHash = BinaryFileHelper.ReadHash128(reader, swap);
761+
info.TypeTreeStructureHash = BinaryFileHelper.ReadHash128(reader, swap);
755762

756763
if (!enableTypeTree)
757764
return info;

Documentation/command-serialized-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Each element of `typeTrees` and `serializedReferenceTypeTrees` in the JSON outpu
285285
| `isStrippedType` | `true` for types representing prefab-stripped objects (the `stripped` keyword in YAML). Orthogonal to TypeTree presence. |
286286
| `scriptTypeIndex` | Index into the file's MonoScript reference list. `-1` for native Unity types. |
287287
| `scriptID` | 128-bit hash (MD4 of assembly + namespace + class name) identifying the MonoScript. All-zeros when not applicable. |
288-
| `oldTypeHash` | Hash of the TypeTree content as originally written; used for compatibility checking at load time. |
288+
| `typeTreeStructureHash` | MD4 hash of the TypeTree structure as originally written; used for compatibility checking at load time. |
289289
| `typeTreeContentHash` | XXH3 hash of the TypeTree blob. All-zeros for files with version < 23. |
290290
| `typeTreeSerializedSize` | Byte size of the TypeTree blob for this entry. `0` when `inlineTypeTree` is false. |
291291
| `inlineTypeTree` | `true` when the TypeTree blob is present inline in the file's metadata. |

0 commit comments

Comments
 (0)