Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | jagc |
I’ve been trying to work around this, banging my head, for 2 days now. XD
I know this can be solved via dirty, spaghetti code and shove all audio into their respective scripts/scenes. But i’m too stubborn and i want this to work.
Case:
- I want to play all my audio from a singleton.
- I want a scene with a library of all my audio.
- Ideally, i want to call it from any script like this:
audioManager.play("confirmButton")
well, ideally.
Situation:
- I’ve read the documentation about singletons over and over and over and …
- watched all the yt videos about gdscript singletons, inheritance, packaging scenes, scene trees, audio manipulation. But apparently, this isn’t enough.
- BTW, this would be my 3rd time using a singleton.
- But this is my 1st time:
- making a scene (audioPlayer.tscn),
- creating a script for the root node of that scene (audioManager.gd),
- making THAT script i just made into a singleton.
Now, i made an awesome dirty spaghetti code but with this pattern still, just to make it work. I’m at the stage where at least it’s recognizing (i guess?) the children nodes of the root node of audioPlayer.tscn
Printing the properties of the node is telling me that it SHOULD BE WORKING. But I’m here, so it’s not.
audioPlayer.tscn
- audioPlayer (Node)
- gameBgMusic (AudioStreamPlayer)
- confirmButton (AudioStreamPlayer)
- spring (AudioStreamPlayer2D)
- shortJump (AudioStreamPlayer2D)
- longJump (AudioStreamPlayer2D)
menu.gd (Just to call the function in the singleton)
extends Node func workNowPlsForCryingOutLoud(): $"/root/audioManager".play("confirmButton")
audioManager.gd (Singleton)
extends Node func play(sound = null): if sound == null: return else: var s = ResourceLoader.load("res://scenes/audioPlayer.tscn") var scene = s.instance() ############################################################### # Honestly? IDK if this is getting gameBgMusic or confirmButton var music = scene.get_child(0) ############################################################### music.volume_db = 100 music.play() # There is no sound coming out. ``` if music.playing == false: print('not playing') else: print('playing') print('paused: ' + str(music.stream_paused)) print('pitch_scale: ' + str(music.pitch_scale)) print('mix_target: ' + str(music.mix_target)) print('bus: ' + str(music.bus)) print('autoplay: ' + str(music.autoplay)) print('volume_db: ' + music.volume_db) ```
What’s the output of that beautiful pillar of print, you may ask?
- playing
- paused: False
- pitch_scale: 1
- mix_target: 0
- bus: Master
- autoplay: True
- 100
Just in case someone asks. Yes, i checked my speakers if they were on and my volume if it was high enough. I even cranked it up to 100 while testing it. I also checked if there is actual audio output via YT, Spotify.
Someone save me from insanity. >.<
Godot 3.1.1