# How to Access Component Data from an Entity?

**URL:** <https://forum.8thwall.com/t/how-to-access-component-data-from-an-entity/3072>\
**Category:** Technical Support\
**Created:** [October 7, 2024, 9:13am UTC](https://forum.8thwall.com/t/how-to-access-component-data-from-an-entity/3072 "2024-10-07T09:13:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Camilo\_MEDINA](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@Camilo\_MEDINA](https://forum.8thwall.com/u/Camilo_MEDINA)\
**Post date:** [October 7, 2024, 9:13am UTC](https://forum.8thwall.com/t/how-to-access-component-data-from-an-entity/3072/1 "2024-10-07T09:13:09Z")

</div>

Hello,

I’m having trouble understanding how to access data from components in other entities, as well as how to access another component’s data within the same entity.  
The documentation isn’t very clear.

For example, I have two components:

**Component One:**

```auto
import * as ecs from '@8thwall/ecs' // This is how you access the ecs library.

ecs.registerComponent({
  name: 'component-one',
  schema: {
    // Add data that can be configured on the component.
    age: ecs.i32,
  },
  schemaDefaults: {
    // Add defaults for the schema fields.
    age: 15,
  },
  data: {
    // Add data that cannot be configured outside of the component.
    pet: ecs.string,
  },
  add: (world, component) => {
    // Runs when the component is added to the world.
    component.data.pet = 'dog'
  },
})

```

**Component Two:**

```auto
import * as ecs from '@8thwall/ecs' // This is how you access the ecs library.

ecs.registerComponent({
  name: 'component-two',
  schema: {
    // Add data that can be configured on the component.

  },
  schemaDefaults: {
    // Add defaults for the schema fields.
  },
  data: {
    // Add data that cannot be configured outside of the component.

  },
  add: (world, component) => {
    // Runs when the component is added to the world.
  },

```

These components might be in the same entity or in different ones.

- How can I access the `age` and `pet` values from **Component Two**?
- What does `ecs.getAttribute()` do?

Thank you!

---

<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 7, 2024, 4:03pm UTC](https://forum.8thwall.com/t/how-to-access-component-data-from-an-entity/3072/2 "2024-10-07T16:03:40Z")

</div>

Data isn’t accessible outside the current entity. To work around this, you’ll need to either use an event listener pattern or create an object that represents your component outside of the registration, which you can then import and use an instance of.
