utopia-rise / fmod-gdextension

FMOD Studio GDExtension bindings for the Godot game engine
MIT License
438 stars 48 forks source link

How to handle warning "No listeners are set!" #218

Closed 3ter closed 4 months ago

3ter commented 4 months ago

I've added an FmodListener2D both to my master scene and to the player scene but still the error pops up when I change rooms (which doesn't free the master scene).

Original warning:

W 0:00:08:0021   FmodManager.gd:8 @ _process(): FMOD Sound System: No listeners are set!void __cdecl godot::FmodServer::_set_listener_attributes(void)src\fmod_server.cpp251
  <C++ Source>   core/variant/variant_utility.cpp:1111 @ push_warning()
  <Stack Trace>  FmodManager.gd:8 @ _process()

Please help me understand the concept better.

piiertho commented 4 months ago

Hello ! This means you don't have any listener set, or you don't have any valid node attached to listeners. Can you provide your scene structure ?

3ter commented 4 months ago

So I thought I'd only need a listener on the player (as it can move in the 2D space) but then the warning is triggered in the main menu (below UI in the screenshot) the first time. image When the room is switched then (so starting room below is replaced by another one) the warning is triggered again.

EDIT: I just saw that there's a built-in AudioListener2D node. This has a current property to enable/disable it. Isn't this needed for the FmodListener2D as well? Or can you listen from multiple positions at once (sounds confusing... pun not intended).

I saw https://fmod-gdextension.readthedocs.io/en/latest/user-guide/3-nodes/#fmod-listeners, but it didn't really help there.

piiertho commented 4 months ago

So I thought I'd only need a listener on the player (as it can move in the 2D space) but then the warning is triggered in the main menu (below UI in the screenshot) the first time. image When the room is switched then (so starting room below is replaced by another one) the warning is triggered again.

EDIT: I just saw that there's a built-in AudioListener2D node. This has a current property to enable/disable it. Isn't this needed for the FmodListener2D as well? Or can you listen from multiple positions at once (sounds confusing... pun not intended).

I saw https://fmod-gdextension.readthedocs.io/en/latest/user-guide/3-nodes/#fmod-listeners, but it didn't really help there.

AudioListener2D has nothing to do with fmod, it comes from godot builtin sound engine.
When you switch scene you don't have a listener set for few moment, so it will print the warn.
It should stop printing it when you add back a listener.

3ter commented 4 months ago

I do know that they are unrelated. I just had two FmodListener2D and wanted to know how they work together. It seems they don't.

So I suppose I can only have one FmodListener2D in the scene tree at a given time and should reparent it from the main scene to the player when it's instantiated. Is that all correct?

Thanks a lot for your help so far, I do appreciate it!

piiertho commented 4 months ago

I do know that they are unrelated. I just had two FmodListener2D and wanted to know how they work together. It seems they don't.

  • When I have 2 FmodListener2D the one attached to the player seems to take precedence (independend from the index setting on both nodes) and the warning is thrown on scene switch.
  • When I only have 1 FmodListener2D attached to the main scene then no warnings are printed (but I suppose I loose the ability for spatial audio according to the player's position).

So I suppose I can only have one FmodListener2D in the scene tree at a given time and should reparent it from the main scene to the player when it's instantiated. Is that all correct?

Thanks a lot for your help so far, I do appreciate it!

You don't lose spatialisation with only one listener.
If you want to setup more listeners you have to set listeners indexes in node, but you also have to change listener count in project settings: image

3ter commented 4 months ago

So for a scene change you recommend to reparent the same listener or attach a new one to a scene higher up in the hierarchy so there's always one listener available?

piiertho commented 4 months ago

So for a scene change you recommend to reparent the same listener or attach a new one to a scene higher up in the hierarchy so there's always one listener available?

I think the warning is not important. Fmod will provide you a default listener without position until you re-add one.

3ter commented 4 months ago

Even using reparent() the FMOD sound system emits this warning. I can't think of a way to get around it. Thank you for your ongoing support. If you've got a project to share where it's done, I'd be happy to check it out 🙂 .

3ter commented 4 months ago

Just wanted to add that I managed to get rid of the error by making sure the listener added to the main scene is only then freed, when there already is another one ready. The trick was to use the tree_entered signal accordingly.

func start_game() -> void:
    $BackgroundMusic.play()

    room_path_to_load = STARTING_ROOM
    spawn_point_to_load = STARTING_SPAWN_POINT
    on_current_room_freed()

    current_room.tree_entered.connect(on_starting_room_loaded)

func on_starting_room_loaded() -> void:
    $FmodListener2D.queue_free()
    room_changed.emit()