justin
New Member
Posts: 20
Posts: 20
|
Post by justin on Oct 18, 2020 20:22:49 GMT
When using the AmbientSound component on my scene, when I press play I receive the following error message:
There is no Master Audio prefab in this Scene. Subsequent method calls will fail. UnityEngine.Debug:LogError(Object) DarkTonic.MasterAudio.MasterAudio:get_Instance() (at Assets/Plugins/DarkTonic/MasterAudio/Scripts/Singleton/MasterAudio.cs:8607) DarkTonic.MasterAudio.MasterAudio:SetupAmbientNextFrame(AmbientSound) (at Assets/Plugins/DarkTonic/MasterAudio/Scripts/Singleton/MasterAudio.cs:8163) DarkTonic.MasterAudio.AmbientSound:OnEnable() (at Assets/Plugins/DarkTonic/MasterAudio/Scripts/Events/AmbientSound.cs:43)
My project is set up so that I have a "Main" scene that contains my GameManager, MasterAudio, and a bunch of general things. And then I have each game level (scene) loaded via the SceneManager. At runtime when I run the game and load a scene, I get that error above. I notice in the plugin it's trying to find the MasterAudio component by using:
_instance = (MasterAudio)GameObject.FindObjectOfType(typeof(MasterAudio));
However, FindObjectOfType cannot find objects that are in other scenes even if they're both loaded. Is there a work around for this that others have used?
Thank you in advance.
|
|
|
Post by DarkTonic Dev on Oct 18, 2020 20:48:58 GMT
|
|
justin
New Member
Posts: 20
Posts: 20
|
Post by justin on Oct 18, 2020 21:23:55 GMT
Okay, this is pretty hacky and I'll likely figure out a more elegant way to do this, but as a general theory it works so essentially just disable the AmbientSound component for the first frame. It seems it just doesn't like that the MasterAudio isn't in the scene in the first frame, but if you wait until the next frame, then it finds the MasterAudio. Thanks for linking that other post as it gave me the hint to enable/disable.
// AmbientSound.cs
private void Start() { StartCoroutine(DelayStart()); }
// ReSharper disable once UnusedMember.Local void OnEnable() {
}
IEnumerator DelayStart() { this.enabled = false; yield return new WaitForEndOfFrame(); this.enabled = true; MasterAudio.SetupAmbientNextFrame(this); }
|
|
|
Post by DarkTonic Dev on Oct 18, 2020 23:06:10 GMT
It seems it just doesn't like that the MasterAudio isn't in the scene in the first frame. I'm not sure I agree with that statement. But it depends what all you're doing in your Scenes. The final sentence in the linked thread sums it up. You will need to make sure there's a MasterAudio game object in the Hierarchy somewhere before AmbientSound scripts are enabled.So I'm trying to figure out how that would happen, because that's the only reason you'd need to do the disable / enable thing. Make sure that Master Audio object is in the Scene before (or at the same time as ) the Ambient Sound scripts that depend on it. Then the Script Execution Order will take care of the rest. If that's not how you have it set up, there's really no way to make that work aside from the workaround. I believe that's from loading things in a decidedly wrong order if you don't have it set up that way. -Brian
|
|