From b5bf5d8a91da5c7695d03afbd9f388e8ae256a43 Mon Sep 17 00:00:00 2001 From: AdrianTheFrog Date: Sun, 16 Nov 2025 22:13:36 -0500 Subject: [PATCH 1/2] fix creating resources multiple times --- package/Runtime/GaussianSplatRenderer.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/package/Runtime/GaussianSplatRenderer.cs b/package/Runtime/GaussianSplatRenderer.cs index 9e080b97..500ce518 100644 --- a/package/Runtime/GaussianSplatRenderer.cs +++ b/package/Runtime/GaussianSplatRenderer.cs @@ -474,14 +474,23 @@ public void EnsureSorterAndRegister() public void OnEnable() { - m_FrameCounter = 0; - if (!resourcesAreSetUp) - return; + var curHash = m_Asset ? m_Asset.dataHash : new Hash128(); - EnsureMaterials(); - EnsureSorterAndRegister(); + //OnEnable will run multiple times when entering play mode from the editor + if (m_PrevAsset != m_Asset || m_PrevHash != curHash) + { + m_PrevAsset = m_Asset; + m_PrevHash = curHash; - CreateResourcesForAsset(); + m_FrameCounter = 0; + if (!resourcesAreSetUp) + return; + + EnsureMaterials(); + EnsureSorterAndRegister(); + + CreateResourcesForAsset(); + } } void SetAssetDataOnCS(CommandBuffer cmb, KernelIndices kernel) From dad275215ca92a7fec8aba2b6f53e6cf4dc6cb80 Mon Sep 17 00:00:00 2001 From: AdrianTheFrog Date: Sun, 16 Nov 2025 22:31:08 -0500 Subject: [PATCH 2/2] keep prior behavior when resources are not set up --- package/Runtime/GaussianSplatRenderer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/Runtime/GaussianSplatRenderer.cs b/package/Runtime/GaussianSplatRenderer.cs index 500ce518..5bfdf86b 100644 --- a/package/Runtime/GaussianSplatRenderer.cs +++ b/package/Runtime/GaussianSplatRenderer.cs @@ -479,13 +479,13 @@ public void OnEnable() //OnEnable will run multiple times when entering play mode from the editor if (m_PrevAsset != m_Asset || m_PrevHash != curHash) { - m_PrevAsset = m_Asset; - m_PrevHash = curHash; - m_FrameCounter = 0; if (!resourcesAreSetUp) return; + m_PrevAsset = m_Asset; + m_PrevHash = curHash; + EnsureMaterials(); EnsureSorterAndRegister();