How do I switch AudioStreamInteractive clips in code?

Godot Version

4.3.stable

Question

How do I switch between AudioStreamInteractive clips with code, similar to the parameter that shows up in the editor? This may be a really dumb question but I really cant find anything out.
My closest guess would be the add_transition() function, but from what the docs say I think it just adds a transition, like in the transition editor.

Yeah, I had to do a little research just now to figure it out; it’s not immediately obvious how this AudioStream should be used. From the looks of it, though, it appears similar in nature to the animation system(s).

To play a specific clip, you can use the following line of code:

$"AudioStreamPlayer".get_stream_playback().switch_to_clip_by_name("NAME")

Thanks Reddit

In terms of where these functions actually originate, get_stream_playback() is found in AudioStreamPlayer and returns an AudioStreamPlayback. Your AudioStreamInteractive makes use of a AudioStreamPlaybackInteractive to playback sound (which is a AudioStreamPlayback through inheritence) – notice the difference in naming. It is the AudioStreamPlaybackInteractive which is capable of changing the clip via either switch_to_clip() or switch_to_clip_by_name().

It sure got me confused!

For a simplified description:
All AudioStreamPlayers make use of a playback instance at run-time (AudioStreamPlayback). Therefore, it is the playback instance whose state must be changed. As far as I can tell, the AudioStream resources (not playbacks) just act as a blueprint for all its instances.


Here are the class references (listed in order of ownership or inheritance):

2 Likes

Oh, I see! Many thanks!

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