Hi. Unity newbie here. I’m currently creating an app which has multiple scenes, and music manager object that persists when changin scene. I also have a separate controller object that allows to control the options in music manager. Everything works fine, execpt that I can’t get a reference to music manager from any other scene aside from the one they both are initially loaded in.
So basically I’d like to be able to have multiple audio controllers that have access to the same audiosource throughout all the scenes.
I can’t post the code here now, but I hope someone could give me a general idea as to how I should proceed with this problem.
You can use Object.DontDestroyOnLoad on your AudioSources so they are not destroy between scenes loading. You can do the same for your manager if it is a component.
Thanks. I tried to use DDOL on the manager as well. It moves to the next scene, but I still don’t get how to get the actual reference. I just need to put it into the buttons of the manager so I can control the music.
There are multiple ways to achieve that. The best solution right now is to use ScripteableObject. Here is an article explaining how to use them. I recommended reading the whole thing but what you need is in the Architect for Events.
well another - probably easier at this stage option - would be to use Singleton pattern
/ lookup unity specific one/s since they need to take care of couple of additional things wrt game objects + scene loading to be sure
You are right. For a long time, singleton was the way to go and still a good solution. Singleton has some cons, so we shifted to Scriptable Events as best practice. But use whatever you feel more comfortable with @djoku .