From 763af02d05f51e980ab86206045a39e26aa73104 Mon Sep 17 00:00:00 2001 From: Rui Carvalho Couto Date: Fri, 17 Jul 2026 15:43:37 +0100 Subject: [PATCH 1/2] Fix Unity 6.4 Object ID compatibility --- CHANGELOG.md | 2 ++ Runtime/GsplatRendererImpl.cs | 12 ++++++------ Runtime/GsplatResourceManager.cs | 17 +++++++++++------ Runtime/GsplatSorter.cs | 6 +++--- Runtime/GsplatUtils.cs | 9 +++++++++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20d4700..7629e13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed PLY header parsing to count only vertex element properties. The package now supports PLY files exported by Apple's [ml-sharp](https://github.com/apple/ml-sharp). ([#33](https://github.com/wuyize25/gsplat-unity/pull/33) by [@TakashiYoshinaga](https://github.com/TakashiYoshinaga)) +- Fixed compilation errors on Unity 6.4 and later caused by the obsoletion of `Object.GetInstanceID()`, while preserving compatibility with older Unity versions. + ## [1.3.0] - 2026-05-23 ### Added diff --git a/Runtime/GsplatRendererImpl.cs b/Runtime/GsplatRendererImpl.cs index efe457d..bd4f6a5 100644 --- a/Runtime/GsplatRendererImpl.cs +++ b/Runtime/GsplatRendererImpl.cs @@ -17,7 +17,7 @@ public class GsplatRendererImpl GsplatAsset m_gsplatAsset; public uint m_remainingCount = 0; public Bounds m_bounds; - int m_gsplatAssetID; + ulong m_gsplatAssetID; public GsplatResource GsplatResource; public GraphicsBuffer OrderBuffer { get; private set; } @@ -39,7 +39,7 @@ public class GsplatRendererImpl uint m_sortsBeforeRecomputeCutouts = 0; public bool ComputeSortRequired = true; public bool ComputeCutoutsRequired = true; - Dictionary m_prevCamTransforms; + Dictionary m_prevCamTransforms; GsplatCutout.ShaderData[] m_cutoutsData; uint m_prevSplatCount; @@ -47,7 +47,7 @@ public class GsplatRendererImpl public GsplatRendererImpl(uint splatCount) { SplatCount = splatCount; - m_prevCamTransforms = new Dictionary(); + m_prevCamTransforms = new Dictionary(); CreateResources(splatCount); CreatePropertyBlock(); } @@ -134,7 +134,7 @@ public void DispatchInitOrder(GsplatCutout[] cutouts, Matrix4x4 matrixWorld, boo public void BindGsplatAsset(GsplatAsset gsplatAsset, bool asyncUpload = false) { Debug.Assert(m_gsplatAssetID == 0); - m_gsplatAssetID = gsplatAsset.GetInstanceID(); + m_gsplatAssetID = GsplatUtils.GetObjectId(gsplatAsset); m_gsplatAsset = gsplatAsset; GsplatResource = GsplatResourceManager.Get(gsplatAsset); gsplatAsset.SetupMaterialPropertyBlock(m_propertyBlock, GsplatResource); @@ -193,7 +193,7 @@ public void RefreshOnCameraMove() { foreach (var cam in Camera.allCameras) { - var id = cam.GetInstanceID(); + var id = GsplatUtils.GetObjectId(cam); if (m_prevCamTransforms.TryGetValue(id, out (Vector3, Vector3) prevCamTransform)) { (Vector3 prevCamPos, Vector3 prevCamRot) = prevCamTransform; @@ -209,7 +209,7 @@ public void RefreshOnCameraMove() } else { - m_prevCamTransforms.Add(cam.GetInstanceID(), (cam.transform.position, cam.transform.eulerAngles)); + m_prevCamTransforms.Add(id, (cam.transform.position, cam.transform.eulerAngles)); ForceRefresh(); } } diff --git a/Runtime/GsplatResourceManager.cs b/Runtime/GsplatResourceManager.cs index 39b1d9e..cdbfb76 100644 --- a/Runtime/GsplatResourceManager.cs +++ b/Runtime/GsplatResourceManager.cs @@ -11,11 +11,11 @@ class Cache public int RefCount; } - static readonly Dictionary k_resourceCache = new(); + static readonly Dictionary k_resourceCache = new(); public static GsplatResource Get(GsplatAsset asset) { - var key = asset.GetInstanceID(); + var key = GsplatUtils.GetObjectId(asset); if (k_resourceCache.TryGetValue(key, out var cache)) { cache.RefCount++; @@ -33,14 +33,19 @@ public static GsplatResource Get(GsplatAsset asset) public static void Release(GsplatAsset asset) { - Release(asset.GetInstanceID()); + Release(GsplatUtils.GetObjectId(asset)); } public static void Release(int instanceID) { - if (instanceID == 0) + Release(unchecked((uint)instanceID)); + } + + internal static void Release(ulong objectID) + { + if (objectID == 0) return; - if (!k_resourceCache.TryGetValue(instanceID, out var cache)) + if (!k_resourceCache.TryGetValue(objectID, out var cache)) { Debug.LogWarning("Trying to release a GPU resource that is not cached."); return; @@ -49,7 +54,7 @@ public static void Release(int instanceID) cache.RefCount--; if (cache.RefCount != 0) return; cache.Resource.Dispose(); - k_resourceCache.Remove(instanceID); + k_resourceCache.Remove(objectID); } } } diff --git a/Runtime/GsplatSorter.cs b/Runtime/GsplatSorter.cs index db476eb..4f29392 100644 --- a/Runtime/GsplatSorter.cs +++ b/Runtime/GsplatSorter.cs @@ -68,7 +68,7 @@ public void Dispose() readonly HashSet m_gsplats = new(); readonly HashSet m_camerasInjected = new(); readonly List m_activeGsplats = new(); - readonly HashSet m_warnedUncompressed = new(); + readonly HashSet m_warnedUncompressed = new(); GsplatSortPass m_sortPass; public const string k_passName = "SortGsplats"; const string k_depthPassName = "Gsplat.ComputeDepth"; @@ -109,7 +109,7 @@ public void UnregisterGsplat(IGsplat gsplat) return; if (gsplat is UnityEngine.Object obj) - m_warnedUncompressed.Remove(obj.GetInstanceID()); + m_warnedUncompressed.Remove(GsplatUtils.GetObjectId(obj)); m_globalRenderer.MarkGlobalBuffersDirty(); @@ -158,7 +158,7 @@ bool CanRenderGlobally() { if (gs.GsplatResource is GsplatResourceSpark) continue; var obj = gs as UnityEngine.Object; - var id = obj ? obj.GetInstanceID() : 0; + var id = obj ? GsplatUtils.GetObjectId(obj) : 0; if (m_warnedUncompressed.Add(id)) Debug.LogWarning( $"[GsplatSorter] '{obj?.name}' uses an uncompressed asset; global sort requires every active renderer to use SPARK compression. Disabling global sort for this scene — all renderers fall back to per-renderer rendering."); diff --git a/Runtime/GsplatUtils.cs b/Runtime/GsplatUtils.cs index b364996..91b61ba 100644 --- a/Runtime/GsplatUtils.cs +++ b/Runtime/GsplatUtils.cs @@ -12,6 +12,15 @@ public static class GsplatUtils public const string k_PackagePath = "Packages/wu.yize.gsplat/"; public static readonly Version k_Version = new("1.4.0"); + internal static ulong GetObjectId(UnityEngine.Object obj) + { +#if UNITY_6000_4_OR_NEWER + return EntityId.ToULong(obj.GetEntityId()); +#else + return unchecked((uint)obj.GetInstanceID()); +#endif + } + // radix sort etc. friendly, see http://stereopsis.com/radix.html public static uint FloatToSortableUint(float f) { From d4c5dad7454089002c7b6fbff77754dbc6fe939a Mon Sep 17 00:00:00 2001 From: wuyize Date: Sun, 19 Jul 2026 17:23:31 +0800 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f5ead4..277fcf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed PLY header parsing to count only vertex element properties. The package now supports PLY files exported by Apple's [ml-sharp](https://github.com/apple/ml-sharp). ([#33](https://github.com/wuyize25/gsplat-unity/pull/33) by [@TakashiYoshinaga](https://github.com/TakashiYoshinaga)) -- Fixed compilation errors on Unity 6.4 and later caused by the obsoletion of `Object.GetInstanceID()`, while preserving compatibility with older Unity versions. +- Fixed compilation errors on Unity 6.4 and later caused by the obsoletion of `Object.GetInstanceID()`, while preserving compatibility with older Unity versions. ([#41](https://github.com/wuyize25/gsplat-unity/pull/41) by [@RuiCarvalhoCouto](https://github.com/RuiCarvalhoCouto)) ## [1.3.0] - 2026-05-23