- Home /
How is this function parameter magically disappearing?
For starters, I'm using C#.
I have an AudioMixer class, which is a MonoBehaviour, and in which I've defined a static method:
public static void PlaySound(string name) ...
There is an instance of the AudioMixer in the scene. Objects in the scene trigger sounds by doing:
AudioMixer.PlaySound("My Sound Name");
This works fine as long as I don't change scenes. But if I start scene A, and then from scene A load into scene B, then in scene B I get a very odd behavior: the "name" parameter of AudioMixer.PlaySound is always an empty string, regardless of what was passed in.
So here's a call:
Debug.Log(name + " is playing sound: " + m_soundName);
AudioMixer.PlaySound(m_soundName);
And here's the parameter validation in AudioMixer.PlaySound:
public static void PlaySound(string name)
{
if(name == "")
Debug.LogWarning("AudioMixer.PlaySound: Requested a sound with no name");
}
And I'll see a sequence of log messages like this:
Unit1 is playing sound: Infantry Shoot
AudioMixer.PlaySound: Requested a sound with no name
I am totally mystified by this behavior. :o
If I start scene B directly, it works. This isn't an issue with the scene configuration itself, or the configuration of that specific AudioMixer instance. The problem seems to be related to destroying one AudioMixer (the one in scene A) and then creating another one (the one in scene B) and then accessing the second one via a static method call.
Is there something about static methods' behavior that I'm just flat-out missing?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Where is the Mistake in my Coin System? 1 Answer
How to call class object from static function? 0 Answers
an object reference is required for the non static field error 1 Answer