I wrote an abstract class CompositeConnector declaring abstract methods. One of them, DrawContent has a default string parameter.
public abstract class CompositeConnector : ScriptableObject
{
// ...
public abstract void DrawContent(GUISkin skin, float zoom_factor, string control_name = "");
// ...
}
Other classes inheriting from CompositeConnector also declare a default parameter.
public class InputTextConnector : CompositeConnector
{
// ...
public override void DrawContent(GUISkin skin, float zoom_factor, string control_name = "")
{
// ...
}
// ...
}
My problem comes when I call this method without the latest parameter.
// Produces the error.
_input_connector.DrawContent(_skin, _zoom_factor);
// No error.
_input_connector.DrawContent(_skin, _zoom_factor, "");
I get an error such as (not at runtime):
Unhandled Exception: System.ArgumentException: Key duplication when
adding: Void DrawContent(UnityEngine.GUISkin, Single, System.String)
As you can see if I set the parameter and don’t rely with the default value I don’t get the error. I tried a lot of various combination but the only solution I found was to not use default parameters.
Is this a known issue? Am I trying to do something wrong here? As it seems to be valid in C# is this coming from Unity?