# STUDIO: apply texture at runtime

**URL:** <https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307>\
**Category:** Technical Support\
**Created:** [October 26, 2024, 11:26am UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307 "2024-10-26T11:26:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Guilmard](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Sam\_Guilmard](https://forum.8thwall.com/u/Sam_Guilmard)\
**Post date:** [October 26, 2024, 11:26am UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/1 "2024-10-26T11:26:00Z")

</div>

Hi there,

Sorry for the really basic question but I’m trying to apply a texture to a sphere entity at runtime. There seem to be no errors with the code but when testing, all I get is a black texture. My current code is:

```
  // Add material
  ecs.Material.set(world, sphereEntity, {
    r: 255,
    g: 255,
    b: 255,
    textureSrc: './assets/ballTexture1.png',
    roughness: 0.5,
    metalness: 0.5,
  })

```

Thank you in advance

---

<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 28, 2024, 4:05pm UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/2 "2024-10-28T16:05:19Z")

</div>

Hi!

Wrap your reference inside of a require and it should work. Here’s an example:

```ts
ecs.Material.set(world, ent, {
  textureSrc: require('./assets/texture_01.png'),
  r: 255,
  g: 255,
  b: 255,
})

```

---

<div class="post-metadata">

**Author:** ![Sam\_Guilmard](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Sam\_Guilmard](https://forum.8thwall.com/u/Sam_Guilmard)\
**Post date:** [October 29, 2024, 1:19pm UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/3 "2024-10-29T13:19:16Z")

</div>

Hi George - Unfortunately I have this error

 ![Screenshot 2024-10-29 at 13.18.16](https://us1.discourse-cdn.com/flex019/uploads/x8thwall/original/2X/3/3d1f8369eb11e6c949bfdc8ce844c16efd105025.png)

---

<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 29, 2024, 4:11pm UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/4 "2024-10-29T16:11:52Z")

</div>

It should still work. However, changing your component file extension from .ts to .js should resolve the error.

---

<div class="post-metadata">

**Author:** ![Sam\_Guilmard](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@Sam\_Guilmard](https://forum.8thwall.com/u/Sam_Guilmard)\
**Post date:** [October 29, 2024, 4:37pm UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/5 "2024-10-29T16:37:23Z")

</div>

success! Thank you mate

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/x8thwall/original/2X/9/9212a857458f1b03a6accb129e0f8cbea408e3e5.png) [@system](https://forum.8thwall.com/u/system)\
**Post date:** [November 2, 2024, 4:37pm UTC](https://forum.8thwall.com/t/studio-apply-texture-at-runtime/3307/6 "2024-11-02T16:37:47Z")

</div>

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.
