Setting parameters of a sound in `FmodEventEmitter2D` is delayed, initially
I am using an FmodEventEmitter2D without autoplay on. I have signals that trigger the setting of parameters and the playing of the sound.
When I set parameters on the node, (either a direct param like volume or a custom FMOD event parameter like "event_parameter/foo/bar", the first time the sound is played, it always defaults to full volume and FMOD defaults for parameters.
Second plays get new parameter values correctly, it's just the first play that doesn't.
Here's an example of code that seems to be working incorrectly, as I've described:
extends FmodEventEmitter2D
func _ready() -> void:
Events.create_button_pressed.connect(on_button_click)
func on_button_click(creation: String):
volume = 0.3
self["event_parameter/Creation_Type/value"] = creation.capitalize()
play()
Edit to add: I have tried the same FMOD sound events with the low level event api. It works correctly.
I found the issue. It seems, when we start an event, we don't properly apply the different properties to it. Instead, we only apply them to an already running event. Because you set the volume and parameter before calling play(), it doesn't apply to it. But on the second call, because the event is already loaded and play() simply restarts it, it works. As a workaround for now, you can test this order (even if it's counter-intuitive), I think it should do the trick.:
func on_button_click(creation: String):
play()
volume = 0.3
self["event_parameter/Creation_Type/value"] = creation.capitalize()
Don't close this issue if it works. We need it open so we can keep track of what to fix.
Thank you! Your suggestion works for the first play, and with a small tweak, it works for all. (Without the tweak below, when the parameter changes from play to play, the sound changed partway through, maybe due to some sort of race condition)
var workaround_done: bool = false
func on_button_click(creation: String):
if not workaround_done:
play()
volume = 0.3
self["event_parameter/Creation_Type/value"] = creation.capitalize()
if workaround_done:
play()
workaround_done = true
We'll start a rework of event emitters next week. Too much problems with current code.
Solved by the latest emitter rework. Will be part of the next release.
Please reopen if the bug persists after next release.