diff --git a/packages/fiber/src/core/utils.ts b/packages/fiber/src/core/utils.ts index 50df421925..0da5cc0523 100644 --- a/packages/fiber/src/core/utils.ts +++ b/packages/fiber/src/core/utils.ts @@ -176,7 +176,11 @@ export function buildGraph(object: THREE.Object3D) { // Disposes an object and all its properties export function dispose void; type?: string; [key: string]: any }>(obj: TObj) { if (obj.dispose && obj.type !== 'Scene') obj.dispose() - for (const key in obj) obj[key].dispose?.() + for (const key in obj) { + const value = obj[key] + if (value.type === 'Scene') continue + value.dispose?.() + } } // Each object in the scene carries a small LocalState descriptor