Error: Invalid set index 'stream' (on base: 'Nil') with value of type 'AudioStreamMP3'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abtin0

Hello,

I’m probably missing something. I try to assign a new audiostream to my AudioStreamPlayer but I get "Invalid set index ‘stream’ (on base: ‘Nil’) with value of type ‘AudioStreamMP3’.

I’m pretty sure I did something similar in my other projects (although they were godot 3).

`

var path = "res://audio/" + str(audio_array.pop_front())

var audio_stream : AudioStream = load(path)

audio_stream_player.stream = audio_stream`

Thanks in advance.

:bust_in_silhouette: Reply From: jgodfrey

The audio_stream_player variable is null. The posted code doesn’t show how you’re setting that variable but it does not contain a valid object reference.

Thanks.
The error was that I was calling the function when a child of the node was ready, so the function executed before the node was ready itself and the onready variables weren’t set.

abtin0 | 2023-05-25 19:24