diff --git a/apps/editor/components/editor/index.tsx b/apps/editor/components/editor/index.tsx index b9356486..6c62fb23 100644 --- a/apps/editor/components/editor/index.tsx +++ b/apps/editor/components/editor/index.tsx @@ -18,6 +18,7 @@ import { CustomCameraControls } from './custom-camera-controls' import { SelectionManager } from './selection-manager' useScene.getState().loadScene() +console.log('Loaded scene in editor') initSpatialGridSync() export default function Editor() { diff --git a/packages/core/src/hooks/spatial-grid/spatial-grid-sync.ts b/packages/core/src/hooks/spatial-grid/spatial-grid-sync.ts index 6668664b..37d083d9 100644 --- a/packages/core/src/hooks/spatial-grid/spatial-grid-sync.ts +++ b/packages/core/src/hooks/spatial-grid/spatial-grid-sync.ts @@ -26,6 +26,14 @@ export function resolveLevelId(node: AnyNode, nodes: Record): s // Call this once at app initialization export function initSpatialGridSync() { const store = useScene + // 1. Initial sync - process all existing nodes + const state = store.getState() + for (const node of Object.values(state.nodes)) { + const levelId = resolveLevelId(node, state.nodes) + spatialGridManager.handleNodeCreated(node, levelId) + } + + // 2. Then subscribe to future changes // Subscribe to all changes store.subscribe((state, prevState) => { diff --git a/packages/core/src/store/use-scene.ts b/packages/core/src/store/use-scene.ts index 89c6bbc0..3f01a087 100644 --- a/packages/core/src/store/use-scene.ts +++ b/packages/core/src/store/use-scene.ts @@ -163,7 +163,8 @@ const useScene = create()( zoneIds: state.zoneIds, }), onRehydrateStorage: (state) => { - console.log('hydration starts') + + console.log('hydrating...') // optional return (state, error) => {