- Home /
How do i create a Soundmanager which is Persistent and ...?
More Information
How do i create a sound manager which is persistent and can be assessed from any scene ?
right now i have one Persistent object as a sound manager which starts at the very first scene and moves along all scenes with 'DontDestroyOnLoad' BUT when i attempt to GetComponent this Object in 'other that first scene' it gives me an error.
So my problem is how do you create a persistent object which are SINGLETON and can be assessed globally through the game ( in all scenes )
This is part of my problem which i am encountering during creating my Gamemanager is there any alternative to GameManager than using a Singleton ?
maybe you can make it a prefab, and have a object with a simple script on it that instantiates the sound prefab.
will it be present in all the scene i go to ?
I have to stop and play the background music on users request on more than one scenarios like 1) start scene ( sound manager option ) 2) inGameScene when user presses escape a small menu popus up for music control
if i have my sound setting on scene other than the first where that object starts -> i get problems. i hope you understood what i described thanks :)
Answer by Owen-Reynolds · Jan 12, 2015 at 03:36 PM
"when i attempt to GetComponent this Object in 'other that first scene' it gives me an error."
That shouldn't be happening. If a dontDestroyOnLoad has parts falling off between scenes or is otherwise acting differently, it's something in your code which is breaking it.
Which component is falling off? Try examining the object in the new scene to see if it looks different. Recheck names. Try reading other components. Try other scenes (add "if Z is pressed, load scene 4".) Try an empty dummy 2nd scene where a single 2-line script tries to use the persistant object. Maybe you've found an obscure bug with DontDoL (for example, I only use it to hold scripts,) but lots of people have been using them for a while, so it's most likely some mistake in your scene 2.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180225im_/https://answers.unity.com/themes/thub/images/avi.jpg)