Skip to content

Commit 0c36a90

Browse files
[CBD-2146] Regenerate TypeIdRegistry from engine type list; add generator
TypeIdRegistry maps Unity ClassIDs (PersistentTypeID) to type names. It is needed as a fallback when a serialized object's TypeTree is unavailable, and when only an ID is known with no file to read at all (e.g. resolving the type of a PackedAsset referenced from a BuildReport). In those cases the name cannot be recovered from the data, so a static map in the tool is required. The map was previously built by hand from the public ClassIDReference page and pruned manually, with no repeatable way to refresh it as new types are added. TypeIdRegistryGenerator (hosted in the UnityFileSystemTestData project) now produces the entries from the live engine type list (UnityEditor.UnityType): runtime types are kept, editor-only types are dropped via the isEditorOnly flag, a small allowlist of BuildReporting types is force-included (needed for BuildReport inspection), and test/fake types from development builds are filtered out. Run it via Tools/Generate TypeIdRegistry or -executeMethod to regenerate the block for a new Unity version.
1 parent 9483aa6 commit 0c36a90

3 files changed

Lines changed: 151 additions & 57 deletions

File tree

‎UnityFileSystem/TypeIdRegistry.cs‎

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace UnityDataTools.FileSystem;
44

55
/// <summary>
6-
/// Registry of common Unity TypeIds mapped to their type names.
6+
/// Registry of Unity TypeIds mapped to their type names.
77
/// Used as a fallback when TypeTree information is not available.
8+
/// The entries below are generated from the live engine type list by the
9+
/// TypeIdRegistryGenerator tool (UnityFileSystemTestData/Assets/Editor/TypeIdRegistryGenerator.cs);
10+
/// regenerate with a current Unity Editor rather than editing them by hand.
811
/// Reference: https://docs.unity3d.com/Manual/ClassIDReference.html
912
/// </summary>
1013
public static class TypeIdRegistry
@@ -74,14 +77,11 @@ public static class TypeIdRegistry
7477
{ 102, "TextMesh" },
7578
{ 104, "RenderSettings" },
7679
{ 108, "Light" },
77-
{ 109, "ShaderInclude" },
78-
{ 110, "BaseAnimationTrack" },
7980
{ 111, "Animation" },
8081
{ 114, "MonoBehaviour" },
8182
{ 115, "MonoScript" },
8283
{ 116, "MonoManager" },
8384
{ 117, "Texture3D" },
84-
{ 118, "NewAnimationTrack" },
8585
{ 119, "Projector" },
8686
{ 120, "LineRenderer" },
8787
{ 121, "Flare" },
@@ -111,8 +111,6 @@ public static class TypeIdRegistry
111111
{ 156, "TerrainData" },
112112
{ 157, "LightmapSettings" },
113113
{ 158, "WebCamTexture" },
114-
{ 159, "EditorSettings" },
115-
{ 162, "EditorUserSettings" },
116114
{ 164, "AudioReverbFilter" },
117115
{ 165, "AudioHighPassFilter" },
118116
{ 166, "AudioChorusFilter" },
@@ -139,13 +137,11 @@ public static class TypeIdRegistry
139137
{ 199, "ParticleSystemRenderer" },
140138
{ 200, "ShaderVariantCollection" },
141139
{ 205, "LODGroup" },
142-
{ 206, "BlendTree" },
143140
{ 207, "Motion" },
144141
{ 208, "NavMeshObstacle" },
145142
{ 210, "SortingGroup" },
146143
{ 212, "SpriteRenderer" },
147144
{ 213, "Sprite" },
148-
{ 214, "CachedSpriteAtlas" },
149145
{ 215, "ReflectionProbe" },
150146
{ 218, "Terrain" },
151147
{ 220, "LightProbeGroup" },
@@ -170,7 +166,6 @@ public static class TypeIdRegistry
170166
{ 240, "AudioMixer" },
171167
{ 241, "AudioMixerController" },
172168
{ 243, "AudioMixerGroupController" },
173-
{ 244, "AudioMixerEffectController" },
174169
{ 245, "AudioMixerSnapshotController" },
175170
{ 246, "PhysicsUpdateBehaviour2D" },
176171
{ 247, "ConstantForce2D" },
@@ -199,26 +194,6 @@ public static class TypeIdRegistry
199194
{ 330, "ParticleSystemForceField" },
200195
{ 331, "SpriteMask" },
201196
{ 363, "OcclusionCullingData" },
202-
{ 900, "MarshallingTestObject" },
203-
{ 1001, "PrefabInstance" },
204-
{ 1002, "EditorExtensionImpl" },
205-
{ 1026, "HierarchyState" },
206-
{ 1028, "AssetMetaData" },
207-
{ 1029, "DefaultAsset" },
208-
{ 1032, "SceneAsset" },
209-
{ 1045, "EditorBuildSettings" },
210-
{ 1048, "InspectorExpandedState" },
211-
{ 1049, "AnnotationManager" },
212-
{ 1051, "EditorUserBuildSettings" },
213-
{ 1101, "AnimatorStateTransition" },
214-
{ 1102, "AnimatorState" },
215-
{ 1105, "HumanTemplate" },
216-
{ 1107, "AnimatorStateMachine" },
217-
{ 1108, "PreviewAnimationClip" },
218-
{ 1109, "AnimatorTransition" },
219-
{ 1111, "AnimatorTransitionBase" },
220-
{ 1113, "LightmapParameters" },
221-
{ 1120, "LightingDataAsset" },
222197
{ 1125, "BuildReport" },
223198
{ 1126, "PackedAssets" },
224199
{ 100000, "int" },
@@ -234,73 +209,56 @@ public static class TypeIdRegistry
234209
{ 100010, "Polygon2D" },
235210
{ 100011, "void" },
236211
{ 19719996, "TilemapCollider2D" },
237-
{ 41386430, "ImportLog" },
238212
{ 55640938, "GraphicsStateCollection" },
239213
{ 73398921, "VFXRenderer" },
240214
{ 156049354, "Grid" },
241215
{ 156483287, "ScenesUsingAssets" },
242216
{ 171741748, "ArticulationBody" },
243-
{ 181963792, "Preset" },
217+
{ 176606843, "PhysicsCoreProjectSettings2D" },
244218
{ 285090594, "IConstraint" },
219+
{ 330615474, "ContentSummary" },
245220
{ 355983997, "AudioResource" },
246-
{ 369655926, "AssetImportInProgressProxy" },
247221
{ 382020655, "PluginBuildInfo" },
248-
{ 387306366, "MemorySettings" },
249-
{ 426301858, "EditorProjectAccess" },
222+
{ 382093023, "UIAnimationBinder" },
223+
{ 392092235, "UIAnimationClip" },
250224
{ 483693784, "TilemapRenderer" },
251-
{ 612988286, "SpriteAtlasAsset" },
252-
{ 638013454, "SpriteAtlasDatabase" },
253225
{ 641289076, "AudioBuildInfo" },
254-
{ 644342135, "CachedSpriteAtlasRuntimeData" },
255226
{ 655991488, "MultiplayerManager" },
256-
{ 662584278, "AssemblyDefinitionReferenceAsset" },
257227
{ 668709126, "BuiltAssetBundleInfoSet" },
258228
{ 687078895, "SpriteAtlas" },
259-
{ 702665669, "DifferentMarshallingTestObject" },
260229
{ 825902497, "RayTracingShader" },
261230
{ 850595691, "LightingSettings" },
262-
{ 877146078, "PlatformModuleSetup" },
263-
{ 890905787, "VersionControlSettings" },
264231
{ 893571522, "CustomCollider2D" },
265232
{ 895512359, "AimConstraint" },
266233
{ 937362698, "VFXManager" },
267-
{ 947337230, "RoslynAnalyzerConfigAsset" },
268-
{ 954905827, "RuleSetFileAsset" },
269234
{ 994735392, "VisualEffectSubgraph" },
270-
{ 994735403, "VisualEffectSubgraphOperator" },
271-
{ 994735404, "VisualEffectSubgraphBlock" },
272-
{ 1001480554, "Prefab" },
273-
{ 1114811875, "ReferencesArtifactGenerator" },
274-
{ 1152215463, "AssemblyDefinitionAsset" },
275-
{ 1154873562, "SceneVisibilityState" },
235+
{ 1096314112, "BlockShaderSyntaxTree" },
236+
{ 1096314113, "BlockShaderContainer" },
237+
{ 1096314114, "BlockShaderErrors" },
238+
{ 1120581460, "RenderAs2D" },
239+
{ 1149764431, "BlockShaderSourceArtifact" },
276240
{ 1183024399, "LookAtConstraint" },
277241
{ 1233149941, "AudioContainerElement" },
278-
{ 1268269756, "GameObjectRecorder" },
279242
{ 1307931743, "AudioRandomContainer" },
280-
{ 1325145578, "LightingDataAssetParent" },
281-
{ 1386491679, "PresetManager" },
282243
{ 1403656975, "StreamingManager" },
283244
{ 1480428607, "LowerResBlitTexture" },
284245
{ 1521398425, "VideoBuildInfo" },
285246
{ 1542919678, "StreamingController" },
286-
{ 1557264870, "ShaderContainer" },
287-
{ 1597193336, "RoslynAdditionalFileAsset" },
288247
{ 1652712579, "MultiplayerRolesData" },
289248
{ 1660057539, "SceneRoots" },
290-
{ 1731078267, "BrokenPrefabAsset" },
291249
{ 1740304944, "VulkanDeviceFilterLists" },
292250
{ 1742807556, "GridLayout" },
293251
{ 1773428102, "ParentConstraint" },
252+
{ 1798438448, "D3D12DeviceFilterLists" },
294253
{ 1818360608, "PositionConstraint" },
295254
{ 1818360609, "RotationConstraint" },
296255
{ 1818360610, "ScaleConstraint" },
297256
{ 1839735485, "Tilemap" },
298-
{ 1896753125, "PackageManifest" },
299257
{ 1931382933, "UIRenderer" },
258+
{ 1931382934, "PanelRenderer" },
300259
{ 1953259897, "TerrainLayer" },
301260
{ 1971053207, "SpriteShapeRenderer" },
302261
{ 2058629509, "VisualEffectAsset" },
303-
{ 2058629511, "VisualEffectResource" },
304262
{ 2059678085, "VisualEffectObject" },
305263
{ 2083052967, "VisualEffect" },
306264
{ 2083778819, "LocalizationAsset" },
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Reflection;
6+
using System.Text;
7+
using UnityEditor;
8+
using UnityEngine;
9+
10+
// Generates the s_KnownTypes dictionary entries for UnityDataTools' TypeIdRegistry.cs from the
11+
// live engine type list. The authoritative source is the internal UnityEditor.UnityType database,
12+
// which exposes persistentTypeID, name and isEditorOnly for every registered type. Reflection is
13+
// used because UnityType is internal to the UnityEditor assembly.
14+
//
15+
// Runtime (non-editor-only) types are kept. A few editor-only types are force-included because
16+
// UnityDataTools needs them to inspect BuildReports (see s_IncludeEditorOnlyNames). Test/fake
17+
// types that get compiled into a development editor build are dropped (see s_ExcludeNames /
18+
// s_ExcludePatterns) since they don't exist in a shipped editor.
19+
//
20+
// Run from the Editor via Tools/Generate TypeIdRegistry, or headless:
21+
// Unity.exe -projectPath <thisProject> -batchmode -quit -executeMethod TypeIdRegistryGenerator.Generate
22+
public static class TypeIdRegistryGenerator
23+
{
24+
// Editor-only types that must be kept because UnityDataTools resolves them when inspecting
25+
// BuildReports. These don't follow a naming convention, so they are listed explicitly. The
26+
// set mirrors the IMPLEMENT_REGISTER_CLASS(BuildReporting, ...) macros in
27+
// Modules/BuildReportingEditor; add new BuildReporting types here when they are introduced.
28+
static readonly HashSet<string> s_IncludeEditorOnlyNames = new()
29+
{
30+
"AudioBuildInfo",
31+
"BuildReport",
32+
"BuiltAssetBundleInfoSet",
33+
"ContentSummary",
34+
"PackedAssets",
35+
"PluginBuildInfo",
36+
"ScenesUsingAssets",
37+
"VideoBuildInfo",
38+
};
39+
40+
// Test/fake types registered by a development editor build that are not real runtime classes
41+
// and should never appear in the registry.
42+
static readonly HashSet<string> s_ExcludeNames = new()
43+
{
44+
"NativeObjectType",
45+
"SerializableManagedHost",
46+
"Derived",
47+
"SubDerived",
48+
"SiblingDerived",
49+
"EmptyObject",
50+
"BlobObject",
51+
};
52+
53+
// Name substrings that identify test scaffolding types to drop.
54+
static readonly string[] s_ExcludePatterns = { "Test", "Fake", "Mock", "Dummy" };
55+
56+
[MenuItem("Tools/Generate TypeIdRegistry")]
57+
public static void Generate()
58+
{
59+
// UnityType lives in the same assembly as UnityEditor.Editor.
60+
Type unityType = typeof(Editor).Assembly.GetType("UnityEditor.UnityType");
61+
if (unityType == null)
62+
{
63+
Debug.LogError("TypeIdRegistryGenerator: could not find type UnityEditor.UnityType.");
64+
return;
65+
}
66+
67+
MethodInfo getTypes = unityType.GetMethod("GetTypes", BindingFlags.Public | BindingFlags.Static);
68+
if (getTypes == null)
69+
{
70+
Debug.LogError("TypeIdRegistryGenerator: could not find UnityType.GetTypes().");
71+
return;
72+
}
73+
74+
PropertyInfo idProp = unityType.GetProperty("persistentTypeID");
75+
PropertyInfo nameProp = unityType.GetProperty("name");
76+
PropertyInfo editorOnlyProp = unityType.GetProperty("isEditorOnly");
77+
if (idProp == null || nameProp == null || editorOnlyProp == null)
78+
{
79+
Debug.LogError("TypeIdRegistryGenerator: UnityType is missing an expected property (persistentTypeID/name/isEditorOnly).");
80+
return;
81+
}
82+
83+
var entries = new List<(int id, string name)>();
84+
foreach (var type in (IEnumerable)getTypes.Invoke(null, null))
85+
{
86+
var id = (int)idProp.GetValue(type);
87+
var name = (string)nameProp.GetValue(type);
88+
89+
// Id 0 (Object) is treated as an error condition by callers, not a real type to map.
90+
if (id == 0 || string.IsNullOrEmpty(name))
91+
continue;
92+
93+
if (IsExcluded(name))
94+
continue;
95+
96+
if ((bool)editorOnlyProp.GetValue(type) && !s_IncludeEditorOnlyNames.Contains(name))
97+
continue;
98+
99+
entries.Add((id, name));
100+
}
101+
102+
entries.Sort((a, b) => a.id.CompareTo(b.id));
103+
104+
var sb = new StringBuilder();
105+
int lastId = int.MinValue;
106+
foreach (var (id, name) in entries)
107+
{
108+
if (id == lastId)
109+
Debug.LogWarning($"TypeIdRegistryGenerator: duplicate persistentTypeID {id} (\"{name}\").");
110+
lastId = id;
111+
112+
sb.AppendLine($" {{ {id}, \"{name}\" }},");
113+
}
114+
115+
var outPath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "TypeIdRegistry.block.txt");
116+
File.WriteAllText(outPath, sb.ToString());
117+
118+
Debug.Log($"TypeIdRegistryGenerator: wrote {entries.Count} entries to {outPath}");
119+
}
120+
121+
static bool IsExcluded(string name)
122+
{
123+
if (s_ExcludeNames.Contains(name))
124+
return true;
125+
126+
foreach (var pattern in s_ExcludePatterns)
127+
{
128+
if (name.Contains(pattern))
129+
return true;
130+
}
131+
132+
return false;
133+
}
134+
}

‎UnityFileSystemTestData/Assets/Editor/TypeIdRegistryGenerator.cs.meta‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)