|
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?
|
|
|
Post by DarkTonic Dev on Feb 3, 2021 7:53:54 GMT
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.
-B
|
|
|
Post by Jesse Talavera-Greenberg on Feb 4, 2021 20:10:57 GMT
Thank you, I appreciate it. For now I'll just create a MasterAudio instance in my test suite.
|
|
|
Post by DarkTonic Dev on Feb 4, 2021 20:15:22 GMT
Ok cool.
|
|
|
Post by DarkTonic Dev on Feb 28, 2021 1:57:23 GMT
I was working on a particular hairy issue that's ahead of yours which is almost fixed I believe. I will get to your issue eventually. I know it's been awhile.
-B
|
|
|
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.
Thanks, though!
|
|
|
Post by DarkTonic Dev on Feb 28, 2021 22:55:23 GMT
Ah ok, thanks!
|
|
|
Post by DarkTonic Dev on May 27, 2022 22:12:46 GMT
I am really not sure of a way to make it work the way you want. Something would need to lazy load or find the Master Audio in the scene. Right now we look it up if it's not populated. I'm going to remove this from the roadmap.
-B
|
|