0 votes

Using a global object for music control, with multiple music players so i can switch from calm to tense music quickly. When testing it solo, it's doing what I intend but when queueing it up in any other scene as an AutoLoad I get node not found errors (when directly referencing the child players) or I get null instance on the files (when using an onready variable reference). i am an using randomize to do random selects on tracks but this isn't the issue. (no rng in the Pursuit sequence, because there are segments that link up when the monster loses you). Pretty sure this has something to do with loading. What am I doing wrong?

extends Node2D

var _calmTrack = 0
var _chaseTrack = 0

const _calmTracks = [

const _pursuitLoops = [

const _hiddenLoops = [

const _escapeShots = [

const _sceneBGM = [

## randomize numbers for song pulls, connect end shots back to regular music
func _ready():
    var _out_ = $Timer.connect("timeout",self,"_initialize")

func _initialize():

    if Director._inPursuit == true:

### play calm music
func _calm_music():
    var _myCalm = load(_calmTracks[_calmTrack])
    $Calm.stream = _myCalm

    if Director._inPursuit:

    if Director._inPursuit == false and $Calm.playing == false:

## play tense music
func _pursuit_music():
    var _myChase = load(_pursuitLoops[_chaseTrack])
    $Pursuit.stream = _myChase

    if Director._playerIsHidden == true:

## play suspense music
func _hidden_music():
    var _myHidden = load(_hiddenLoops[_chaseTrack])
    $Hidden.stream = _myHidden

    if Director._inPursuit == false:

## play escape one-shot
func _escape_music():
    var _myEsc = load(_escapeShots[_chaseTrack])
    $Escape.stream = _myEsc

    if $Escape.playing == false:

### event music, direct calls
func _event_music(_resourcePath):
    var _myTrack = load(_resourcePath)
    $Event.stream = _myTrack

    if $Event.playing == false:

## rng function to change song pull
func _shuffle_bgm():
    _calmTrack = randi() % 4
    _chaseTrack = randi() % 4
Godot version v3.4.3.stable.official [242c05d12]
in Engine by (548 points)

1 Answer

+1 vote
Best answer

Autoloaded script never reaches ready(), because it only happens when node gets inside scene tree ( Autoload means that a script is a singleton, away from the tree). You need another node ( inside tree) to reach and menage audio tracks of autoloaded script.

by (7,925 points)
selected by

Correct. Found out i had loaded the script and the node and the script was firing before the node was ready. Changed it to only autoload the node and now the problem is solved. Thank you for the help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.