# Error After Loading To Another Space

**URL:** <https://forum.8thwall.com/t/error-after-loading-to-another-space/8328>\
**Category:** Technical Support\
**Created:** [September 24, 2025, 7:03am UTC](https://forum.8thwall.com/t/error-after-loading-to-another-space/8328 "2025-09-24T07:03:19Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![GeorgeButler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.8thwall.com/georgebutler/32/1903_2.png) [@GeorgeButler](https://forum.8thwall.com/u/GeorgeButler)\
**Post date:** [October 2, 2025, 9:02pm UTC](https://forum.8thwall.com/t/error-after-loading-to-another-space/8328/13 "2025-10-02T21:02:04Z")

</div>

Hi!

I’ve taken a look at the space switching logic and it looks like there might have been an invalid cursor which could be the source of the issue. Here is the fixed version:

```javascript
import * as ecs from '@8thwall/ecs'

ecs.registerComponent({
  name: 'Load Space on Click',
  schema: {
    spaceName: ecs.string,
    hideUIOnClick: ecs.boolean,
    hideInventoryOnClick: ecs.boolean,
    inventoryUI: ecs.eid,
    inventoryUIButton: ecs.eid,
    inventoryUiClosebutton: ecs.eid,
  },
  schemaDefaults: {
    spaceName: 'World Map',
    hideUIOnClick: false,
    hideInventoryOnClick: false,
  },
  data: {
    isLoading: ecs.boolean,
  },
  stateMachine: ({world, eid, schemaAttribute, dataAttribute}) => {
    ecs.defineState('default')
      .initial()
      .onEnter(() => {
        dataAttribute.set(eid, {isLoading: false})
      })
      .listen(eid, ecs.input.UI_CLICK, () => {
        const {hideUIOnClick, hideInventoryOnClick, inventoryUI, inventoryUIButton, inventoryUiClosebutton} = schemaAttribute.get(eid)

        if (hideUIOnClick) {
          window.dispatchEvent(
            new CustomEvent('back-to-map', {detail: {}})
          )
          console.log('[Back to map]: event fired')
        }

        if (hideInventoryOnClick) {
          console.log('disable buttons')
          ecs.Disabled.set(world, inventoryUI)
          ecs.Disabled.remove(world, inventoryUIButton)
          ecs.Disabled.remove(world, inventoryUiClosebutton)
          ecs.Disabled.set(world, eid)
        }
      })
      .listen(eid, ecs.input.UI_RELEASED, () => {
        const {spaceName} = schemaAttribute.get(eid)
        const state = dataAttribute.cursor(eid)
        if (spaceName && !state.isLoading) {
          state.isLoading = true
          console.log('queued space load', spaceName)

          world.time.setTimeout(() => {
            try {
              console.log('loading space', spaceName)
              world.spaces.loadSpace(spaceName)
            } catch (e) {
              console.error('failed to load space', e)
            } finally {
              dataAttribute.set(eid, {isLoading: false})
            }
          }, 1000)
        }
      })
  },
})

```

Also you should always use world.time to set a timeout instead of using the Javascript native timeout.

---

_[View the full topic](https://forum.8thwall.com/t/error-after-loading-to-another-space/8328)._
