Post by Jesse Talavera-Greenberg on Feb 3, 2021 2:17:15 GMT
When certain events occur in my game, I play a sound effect. Generally when I do a MasterAudio instance exists. But not always! My game has a suite of automated tests to verify that the mechanics work correctly. Each test in this suite has a minimal environment; since I'm not testing audio, this environment does not include a MasterAudio instance.
If I call a method to play a sound effect in this scenario -- usually MasterAudio.PlaySoundAndForget -- then MasterAudio will log an error and return failure. The problem with this, however, is that any call to Debug.LogError will cause the running test to fail. I can test MasterAudio.Instance or MasterAudio.SafeInstance for null before playing sound; however, both properties (and any methods that depend on them) will look for an instance using GameObject.FindObjectOfType if necessary. Not only is that slow, but it will allocate an array (even an empty one). Since I'm running the test suite on my game's targeted hardware, I have to be just as mindful about memory usage there as I do in production builds.
With that said, is it possible you could add a way to test for the presence of a MasterAudio instance that doesn't search for an existing one? Alternatively (and ideally simultaneously), is it possible you could add the (optional) ability to silently ignore the lack of a MasterAudio instance by just returning a failure?
I don't know if it's possible or not, I'll need to try some things. As far as the second ask, we can of course make an option to not log an error and just return. But the rest of it is only possible if your first ask is possible, since it uses the Instance property in the check. This is the 4th request in my queue so it may take some weeks to get to it.
Post by Jesse Talavera-Greenberg on Feb 28, 2021 19:01:44 GMT
I appreciate it, but you can actually put this one a little further down on your list if you'd like. I figured out another way around my problem; I have since wrapped all uses of MasterAudio in a service interface. At runtime, this interface delegates to MasterAudio. In my test suite, it does nothing. I probably should've done that from the beginning.