# \[Studio\] world.audio.addSound() no longer exists?

**URL:** <https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621>\
**Category:** Technical Support\
**Created:** [November 17, 2024, 7:17pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621 "2024-11-17T19:17:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Beck](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dylan\_Beck](https://forum.8thwall.com/u/Dylan_Beck)\
**Post date:** [November 17, 2024, 7:17pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/1 "2024-11-17T19:17:22Z")

</div>

Hi there,

Our Studio project has just started throwing an error: `Unhandled promise rejection: TypeError: world.audio.addSound is not a function`

This function seemed to be working fine before but now cannot be used - I checked the docs to see if it has been deprecated or replaced but they still point towards using `addSound()`. We’ve commented out the calls for now and the project’s now working (albeit without sound) - I was wondering if perhaps there was an alternative we should be using?

Cheers,  
Dylan

---

<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:** [November 18, 2024, 4:51pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/2 "2024-11-18T16:51:08Z")

</div>

Thanks for pointing this out! I’ll make sure our docs get updated.

The methods world.audio.(mute/unmute/play/pause/setVolume) are still supported, but audio should now be added to an entity using the [audio component](https://www.8thwall.com/docs/studio/api/ecs/Audio/).

---

<div class="post-metadata">

**Author:** ![Dylan\_Beck](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dylan\_Beck](https://forum.8thwall.com/u/Dylan_Beck)\
**Post date:** [November 20, 2024, 12:59am UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/3 "2024-11-20T00:59:31Z")

</div>

Thanks for the update George!

Just another question for you - once I’ve made an entity with an audio component, how can I fire off a singular sound effect? Music is easy enough by setting loop/autoplay to true, but I’m unsure on how to use a function like `world.audio.play()` to activate an entity’s audio component. Looking at the docs, it doesn’t seem like the component itself has a way to play its corresponding audio file, so I’m a bit lost on where to look next. Perhaps I need to add the audio components to entities at runtime?

---

<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:** [November 20, 2024, 7:26pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/4 "2024-11-20T19:26:40Z")

</div>

The most effective way to play a one-time sound effect is to create an entity with an Audio component specifying the src. Then, use a timeout set to the duration of the sound effect to delete the entity once the sound finishes playing.

---

<div class="post-metadata">

**Author:** ![Dylan\_Beck](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dylan\_Beck](https://forum.8thwall.com/u/Dylan_Beck)\
**Post date:** [November 20, 2024, 11:35pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/5 "2024-11-20T23:35:50Z")

</div>

I gave it a try - works great for looping background music which is created during my audio manager’s add() call.

I have this function which I’m using for creating one-time SFX, which is creating a new entity for each instance as you recommended. I’ve encountered a few issues with it. I’ve also pasted the function I use for looping music (which works great) as a comparison. In both cases, the new entity is added as a child of the audio manager object for organisation’s sake (hence the use of a singleton EID).

The one-time SFX don’t seem to play unless i set `loop: true` in the `ecs.Audio.set()`  
call - I’m not sure of another way to get the audio to play automatically at this stage. I thought that maybe letting the one-time SFX loop is fine, since I also have the timeout function to remove the entity after its first playthrough, the time of which is an `ecs.f32` variable, but for some reason the timeout function causes playback of SFX to be very inconsistent. Sometimes the sound effect plays, sometimes it’s cut off prematurely, and most often, they simply don’t play at all.

Any advice? I wonder if I’m missing something in my function.

```auto
function playOneTimeSFX(world, url, time, volume) {
  if (singletonEID === null) return
  const urlPrefix = 'assets/Audio/'
  const entity = world.createEntity()
  world.setParent(entity, singletonEID)
  ecs.Audio.set(world, entity, {
    url: `${urlPrefix}${url}`,
    volume,
    pitch: 1,
  })

  world.time.setTimeout(() => {
    world.deleteEntity(entity)
  }, time)
}

function startLoopedMusic(world, url, volume) {
  if (singletonEID === null) return

  const urlPrefix = 'assets/Audio/'
  const entity = world.createEntity()
  world.setParent(entity, singletonEID)
  ecs.Audio.set(world, entity, {
    url: `${urlPrefix}${url}`,
    volume,
    pitch: 1,
    loop: true,
  })
}

```

---

<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:** [November 21, 2024, 5:32pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/6 "2024-11-21T17:32:21Z")

</div>

Weird! Could it be that singletonEID isn’t coming through sometimes and that’s causing strange behavior?

---

<div class="post-metadata">

**Author:** ![Dylan\_Beck](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dylan\_Beck](https://forum.8thwall.com/u/Dylan_Beck)\
**Post date:** [November 21, 2024, 9:14pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/7 "2024-11-21T21:14:58Z")

</div>

The singletonEID seems to come through consistently - I tried removing any references to it to see if that would have an effect, but still getting nothing from the SFX. The entities are definitely being created & eventually removed, and the time before removal is long after the duration of the sound itself. The only way I’ve been able to get the SFX to actually sound off is when I set `loop: true`, but then I get the issues I mentioned before. I saw that there’s an autoplay option in the Audio component but I don’t see a way to set it in code - I was wondering if there’s possibly a way to do that?

---

<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:** [November 21, 2024, 9:36pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/8 "2024-11-21T21:36:01Z")

</div>

Autoplay sets `playing` to be true on the component. Weird that it only works with loop. Could it be that the Audio takes a bit to load each time? Can you try delaying the removal of the entity by a second or two and see that works?

---

<div class="post-metadata">

**Author:** ![Dylan\_Beck](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@Dylan\_Beck](https://forum.8thwall.com/u/Dylan_Beck)\
**Post date:** [November 24, 2024, 7:03pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/9 "2024-11-24T19:03:56Z")

</div>

Figured it out! Bit of a silly move on my part - I realised the time variables for deleting the audio components are supposed to be in milliseconds. I was using seconds 😅 Got it working now, thanks for all your help!

---

<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 28, 2024, 7:04pm UTC](https://forum.8thwall.com/t/studio-world-audio-addsound-no-longer-exists/3621/10 "2024-11-28T19:04:25Z")

</div>

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