#Web export game freezes when first playing a sound

1 messages · Page 1 of 1 (latest)

gleaming moon
#

Using Godot 4.3's web export, everything works fine but whenever a sound is played for the first time, the entire game freezes while the sound is loaded.

This also happens when first showing some CPUParticles3D. As soon as the emitter is turned on, the game freezes for ~1sec

Is there a way around this, to make it load the sounds when the scene first loads?

main crypt
#

I've been having the same issue and haven't found a way around it yet, the blog post about audio in web exports in 4.3 (https://godotengine.org/article/progress-report-web-export-in-4-3/) pointed me to the AudioServer.register_stream_as_sample() API, which I try to call for all sound effects to try to load it, but it doesn't seem to have any actual impact

Godot Engine

With single-threaded builds and sample playback, it's now easier than ever to export your game to the Web with Godot 4.3. And more!

supple finch
#

Load the resources beforehand to have them cached. Any load() or preload() call woth their path should do.
It does not matter what you do with the loaded resource.

main crypt
#

Hmm, I thought I was doing that but maybe I was doing it incorrectly.

The way I tried to work around this is by loading all sounds resources in the project in the main menu, so I have a SoundLoader class that looks something like:

const files_to_load: Array[AudioStream] = [
    preload("res://Enemies/Zombie/Sounds/RoundhouseDamage/PUNCH_SQUELCH_HEAVY_01.wav"),
    preload("res://Levels/loop_rain.ogg")
]
func load():
    for stream in files_to_load:
        AudioServer.register_stream_as_sample(stream)

and in my main menu class I create this class and invoke the load function:

func _ready() -> void:
    print(OS.get_name())
    # Register all sounds as samples on web version
    if OS.get_name() == "Web":
        var loader := SoundLoader.new()
        loader.load()
#

The scene I do that in doesn't actually use those resources, is there some optimization that skips all of them because they're not referenced elsewhere?

main crypt
# main crypt The scene I do that in doesn't actually use those resources, is there some optim...

Okay, I think I'm onto something here, I moved that snippet to my main game scene. I think I understand what's going on, the SoundLoader class was probably getting disposed since there weren't any references left over to it so the resources all got deleted and had to be reloaded again in the main scene. I'll move it to an Autoload which I think should keep the resources cached in memory.