From 82a3ba8b2d3110e594c9f3838c917c9d144e7d9a Mon Sep 17 00:00:00 2001 From: varinotmUnity Date: Fri, 28 Nov 2025 17:21:40 -0500 Subject: [PATCH 1/5] fix instance ID warnings --- Editor/EditorCore/HierarchyListener.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Editor/EditorCore/HierarchyListener.cs b/Editor/EditorCore/HierarchyListener.cs index 52d9adac7..309e2dac6 100644 --- a/Editor/EditorCore/HierarchyListener.cs +++ b/Editor/EditorCore/HierarchyListener.cs @@ -28,13 +28,21 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) if (stream.GetEventType(i) == ObjectChangeKind.CreateGameObjectHierarchy) { stream.GetCreateGameObjectHierarchyEvent(i, out CreateGameObjectHierarchyEventArgs data); +#if UNITY_6000_4_OR_NEWER + GameObjectCreatedOrStructureModified(data.entityId); +#else GameObjectCreatedOrStructureModified(data.instanceId); +#endif } // ProBuilderMesh was created by adding from component menu or pasting component else if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectStructure) { stream.GetChangeGameObjectStructureEvent(i, out var data); +#if UNITY_6000_4_OR_NEWER + GameObjectCreatedOrStructureModified(data.entityId); +#else GameObjectCreatedOrStructureModified(data.instanceId); +#endif } else if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectStructureHierarchy) { @@ -47,10 +55,13 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) // probuilder, then destroy. it's not without risk, as we would be relying on string comparison // of names to assume that scene mesh assets were created by probuilder. stream.GetChangeGameObjectStructureHierarchyEvent(i, out var data); - +#if UNITY_6000_4_OR_NEWER + if (UnityEditor.EditorUtility.EntityIdToObject(data.entityId) is GameObject go) +#else #pragma warning disable CS0618 // Type or member is obsolete if (UnityEditor.EditorUtility.InstanceIDToObject(data.instanceId) is GameObject go) #pragma warning restore CS0618 +#endif { var meshes = go.GetComponentsInChildren(); foreach (var mesh in meshes) @@ -62,6 +73,15 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) } } +#if UNITY_6000_4_OR_NEWER + static void GameObjectCreatedOrStructureModified(EntityId entityId) + { + // if the created object is a probuilder mesh, check if it is a copy of an existing instance. + // if so, we need to create a new mesh asset. + if (UnityEditor.EditorUtility.EntityIdToObject(entityId) is GameObject go) + CheckForProBuilderMeshesCreatedOrModified(go); + } +#else static void GameObjectCreatedOrStructureModified(int instanceId) { // if the created object is a probuilder mesh, check if it is a copy of an existing instance. @@ -71,6 +91,7 @@ static void GameObjectCreatedOrStructureModified(int instanceId) #pragma warning restore CS0618 CheckForProBuilderMeshesCreatedOrModified(go); } +#endif static void CheckForProBuilderMeshesCreatedOrModified(GameObject go) { From e1369600de29dbb34daa4603d0ea17a1fcb33863 Mon Sep 17 00:00:00 2001 From: varinotmUnity Date: Fri, 28 Nov 2025 17:22:56 -0500 Subject: [PATCH 2/5] Add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b5e08638..e00846b53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- [PBLD-284] Fixed instance ID obsolescene warning appearing on 6000.4 and newer versions + ## [6.0.8] - 2025-11-17 ### Fixed From 67e2f6277d7bb08dd31bef0c739bf4e0686c0dbd Mon Sep 17 00:00:00 2001 From: varinotmUnity Date: Mon, 1 Dec 2025 13:39:23 -0500 Subject: [PATCH 3/5] make changes more pretty --- Editor/EditorCore/HierarchyListener.cs | 119 ++++++++++++++----------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/Editor/EditorCore/HierarchyListener.cs b/Editor/EditorCore/HierarchyListener.cs index 309e2dac6..a577b2974 100644 --- a/Editor/EditorCore/HierarchyListener.cs +++ b/Editor/EditorCore/HierarchyListener.cs @@ -24,44 +24,28 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) { for (int i = 0, c = stream.length; i < c; ++i) { - // ProBuilderMesh was created via duplicate, copy paste - if (stream.GetEventType(i) == ObjectChangeKind.CreateGameObjectHierarchy) - { - stream.GetCreateGameObjectHierarchyEvent(i, out CreateGameObjectHierarchyEventArgs data); -#if UNITY_6000_4_OR_NEWER - GameObjectCreatedOrStructureModified(data.entityId); -#else - GameObjectCreatedOrStructureModified(data.instanceId); -#endif - } - // ProBuilderMesh was created by adding from component menu or pasting component - else if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectStructure) + var type = stream.GetEventType(i); + + // Case 1: Creation or Structure Change + if (type == ObjectChangeKind.CreateGameObjectHierarchy || + type == ObjectChangeKind.ChangeGameObjectStructure) { - stream.GetChangeGameObjectStructureEvent(i, out var data); -#if UNITY_6000_4_OR_NEWER - GameObjectCreatedOrStructureModified(data.entityId); -#else - GameObjectCreatedOrStructureModified(data.instanceId); -#endif + GameObject go = GetGameObjectFromEvent(ref stream, i, type); + if (go != null) + CheckForProBuilderMeshesCreatedOrModified(go); } - else if (stream.GetEventType(i) == ObjectChangeKind.ChangeGameObjectStructureHierarchy) + // Case 2: Hierarchy Structure Change + else if (type == ObjectChangeKind.ChangeGameObjectStructureHierarchy) { // Note 2 : This needs to be called when using a Prefab>Replace action in the menus to refresh the current // ProBuilder Mesh, this is still a problem in 2023.3 as it does not automatically refresh the mesh // Note 1 : that this is leaking meshes when reverting! in 2023.1+ we handle it correctly, but 2022 and // 2021 have the PPtr reset to the serialized value (null) before we have any access. orphaned - // mesh assets are cleaned up on scene or domain reloads, so we'll live with it. the alternative is - // to find all mesh assets, determine which aren't referenced by any component and owned by - // probuilder, then destroy. it's not without risk, as we would be relying on string comparison - // of names to assume that scene mesh assets were created by probuilder. - stream.GetChangeGameObjectStructureHierarchyEvent(i, out var data); -#if UNITY_6000_4_OR_NEWER - if (UnityEditor.EditorUtility.EntityIdToObject(data.entityId) is GameObject go) -#else -#pragma warning disable CS0618 // Type or member is obsolete - if (UnityEditor.EditorUtility.InstanceIDToObject(data.instanceId) is GameObject go) -#pragma warning restore CS0618 -#endif + // mesh assets are cleaned up on scene or domain reloads, so we'll live with it. + + GameObject go = GetGameObjectFromEvent(ref stream, i, type); + + if (go != null) { var meshes = go.GetComponentsInChildren(); foreach (var mesh in meshes) @@ -72,26 +56,61 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) } } } + + private static GameObject GetGameObjectFromEvent(ref ObjectChangeEventStream stream, int index, ObjectChangeKind kind) + { + #if UNITY_6000_4_OR_NEWER + switch (kind) + { + case ObjectChangeKind.CreateGameObjectHierarchy: + { + stream.GetCreateGameObjectHierarchyEvent(index, out var data); + return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; + } + case ObjectChangeKind.ChangeGameObjectStructure: + { + stream.GetChangeGameObjectStructureEvent(index, out var data); + return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; + } + case ObjectChangeKind.ChangeGameObjectStructureHierarchy: + { + stream.GetChangeGameObjectStructureHierarchyEvent(index, out var data); + return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; + } + } + #else + int instanceId = 0; + switch (kind) + { + case ObjectChangeKind.CreateGameObjectHierarchy: + { + stream.GetCreateGameObjectHierarchyEvent(index, out var data); + instanceId = data.instanceId; + break; + } + case ObjectChangeKind.ChangeGameObjectStructure: + { + stream.GetChangeGameObjectStructureEvent(index, out var data); + instanceId = data.instanceId; + break; + } + case ObjectChangeKind.ChangeGameObjectStructureHierarchy: + { + stream.GetChangeGameObjectStructureHierarchyEvent(index, out var data); + instanceId = data.instanceId; + break; + } + } -#if UNITY_6000_4_OR_NEWER - static void GameObjectCreatedOrStructureModified(EntityId entityId) - { - // if the created object is a probuilder mesh, check if it is a copy of an existing instance. - // if so, we need to create a new mesh asset. - if (UnityEditor.EditorUtility.EntityIdToObject(entityId) is GameObject go) - CheckForProBuilderMeshesCreatedOrModified(go); - } -#else - static void GameObjectCreatedOrStructureModified(int instanceId) - { - // if the created object is a probuilder mesh, check if it is a copy of an existing instance. - // if so, we need to create a new mesh asset. -#pragma warning disable CS0618 // Type or member is obsolete - if (UnityEditor.EditorUtility.InstanceIDToObject(instanceId) is GameObject go) -#pragma warning restore CS0618 - CheckForProBuilderMeshesCreatedOrModified(go); - } -#endif + if (instanceId != 0) + { + #pragma warning disable CS0618 // Type or member is obsolete + return UnityEditor.EditorUtility.InstanceIDToObject(instanceId) as GameObject; + #pragma warning restore CS0618 + } + #endif + return null; + } static void CheckForProBuilderMeshesCreatedOrModified(GameObject go) { From 3c6a3b773db5a11837f30afe3e9961979b2602e4 Mon Sep 17 00:00:00 2001 From: varinotmUnity <89816088+varinotmUnity@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:01:47 -0500 Subject: [PATCH 4/5] Update CHANGELOG.md Co-authored-by: jmcduff-unity <87323996+jmcduff-unity@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e00846b53..44a744938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed -- [PBLD-284] Fixed instance ID obsolescene warning appearing on 6000.4 and newer versions +- [PBLD-284] Fixed instance ID obsolescence warning appearing on 6000.4 and newer versions ## [6.0.8] - 2025-11-17 From d074c1ad36139c45a588e34326e1932c5917ee78 Mon Sep 17 00:00:00 2001 From: varinotmUnity Date: Mon, 8 Dec 2025 11:10:26 -0500 Subject: [PATCH 5/5] fix following PR comment --- Editor/EditorCore/HierarchyListener.cs | 92 ++++++++------------------ 1 file changed, 28 insertions(+), 64 deletions(-) diff --git a/Editor/EditorCore/HierarchyListener.cs b/Editor/EditorCore/HierarchyListener.cs index a577b2974..9c65344d3 100644 --- a/Editor/EditorCore/HierarchyListener.cs +++ b/Editor/EditorCore/HierarchyListener.cs @@ -26,15 +26,18 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) { var type = stream.GetEventType(i); - // Case 1: Creation or Structure Change - if (type == ObjectChangeKind.CreateGameObjectHierarchy || - type == ObjectChangeKind.ChangeGameObjectStructure) + if (type == ObjectChangeKind.CreateGameObjectHierarchy) { - GameObject go = GetGameObjectFromEvent(ref stream, i, type); - if (go != null) - CheckForProBuilderMeshesCreatedOrModified(go); + stream.GetCreateGameObjectHierarchyEvent(i, out var data); + var go = GetGameObject(data); + if (go != null) CheckForProBuilderMeshesCreatedOrModified(go); + } + else if (type == ObjectChangeKind.ChangeGameObjectStructure) + { + stream.GetChangeGameObjectStructureEvent(i, out var data); + var go = GetGameObject(data); + if (go != null) CheckForProBuilderMeshesCreatedOrModified(go); } - // Case 2: Hierarchy Structure Change else if (type == ObjectChangeKind.ChangeGameObjectStructureHierarchy) { // Note 2 : This needs to be called when using a Prefab>Replace action in the menus to refresh the current @@ -42,8 +45,8 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) // Note 1 : that this is leaking meshes when reverting! in 2023.1+ we handle it correctly, but 2022 and // 2021 have the PPtr reset to the serialized value (null) before we have any access. orphaned // mesh assets are cleaned up on scene or domain reloads, so we'll live with it. - - GameObject go = GetGameObjectFromEvent(ref stream, i, type); + stream.GetChangeGameObjectStructureHierarchyEvent(i, out var data); + var go = GetGameObject(data); if (go != null) { @@ -51,66 +54,27 @@ static void ObjectEventChangesPublished(ref ObjectChangeEventStream stream) foreach (var mesh in meshes) EditorUtility.SynchronizeWithMeshFilter(mesh); } - ProBuilderEditor.Refresh(); } } } - - private static GameObject GetGameObjectFromEvent(ref ObjectChangeEventStream stream, int index, ObjectChangeKind kind) - { - #if UNITY_6000_4_OR_NEWER - switch (kind) - { - case ObjectChangeKind.CreateGameObjectHierarchy: - { - stream.GetCreateGameObjectHierarchyEvent(index, out var data); - return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; - } - case ObjectChangeKind.ChangeGameObjectStructure: - { - stream.GetChangeGameObjectStructureEvent(index, out var data); - return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; - } - case ObjectChangeKind.ChangeGameObjectStructureHierarchy: - { - stream.GetChangeGameObjectStructureHierarchyEvent(index, out var data); - return UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; - } - } - #else - int instanceId = 0; - switch (kind) - { - case ObjectChangeKind.CreateGameObjectHierarchy: - { - stream.GetCreateGameObjectHierarchyEvent(index, out var data); - instanceId = data.instanceId; - break; - } - case ObjectChangeKind.ChangeGameObjectStructure: - { - stream.GetChangeGameObjectStructureEvent(index, out var data); - instanceId = data.instanceId; - break; - } - case ObjectChangeKind.ChangeGameObjectStructureHierarchy: - { - stream.GetChangeGameObjectStructureHierarchyEvent(index, out var data); - instanceId = data.instanceId; - break; - } - } - if (instanceId != 0) - { - #pragma warning disable CS0618 // Type or member is obsolete - return UnityEditor.EditorUtility.InstanceIDToObject(instanceId) as GameObject; - #pragma warning restore CS0618 - } - #endif - return null; - } +#if UNITY_6000_4_OR_NEWER + static GameObject GetGameObject(CreateGameObjectHierarchyEventArgs data) => UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; + static GameObject GetGameObject(ChangeGameObjectStructureEventArgs data) => UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; + static GameObject GetGameObject(ChangeGameObjectStructureHierarchyEventArgs data) => UnityEditor.EditorUtility.EntityIdToObject(data.entityId) as GameObject; +#else + static GameObject GetGameObject(CreateGameObjectHierarchyEventArgs data) => InstanceIDToObject(data.instanceId); + static GameObject GetGameObject(ChangeGameObjectStructureEventArgs data) => InstanceIDToObject(data.instanceId); + static GameObject GetGameObject(ChangeGameObjectStructureHierarchyEventArgs data) => InstanceIDToObject(data.instanceId); + + static GameObject InstanceIDToObject(int instanceId) + { +#pragma warning disable CS0618 + return UnityEditor.EditorUtility.InstanceIDToObject(instanceId) as GameObject; +#pragma warning restore CS0618 + } +#endif static void CheckForProBuilderMeshesCreatedOrModified(GameObject go) {