Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Accordingly to this thread, it seems that default parameters aren't supported by C# script in Unity3D environment.

Declaring an optional parameter in a C# scirpt makes Mono Ide complaint about it:

void Foo(int first, int second = 10) // this line is marked as wrong inside Mono IDE

Anyway if I ignore the error message of Mono and run the script in Unity, it works without notify any error inside Unity Console.

Could anyone clarify a little bit this issue? Particularly:

  • Are default parameters allowed inside C# scripts?
  • If yes, are they supported by all platforms?
  • Why Mono complains about them if the actually works?
share|improve this question
In fact you can build in Visual Studio targeting .NET 3.5 with no problems. – felipe Oct 10 '13 at 15:34
up vote 2 down vote accepted
  1. As of Unity 3.1, default arguments are supported in C#. As Mono Develop doesn't support them, so if you're using the debugger you need to select Tools > Preferences > Unity > Debugger and turn off "Build project in MonoDevelop".

  2. Yes supported.

  3. As before C# 4.0, doesn't allow for default parameters. For this reason it was not at Unity3D. Mono complains why, Mono can answer the best. But I think they will add at next version.

share|improve this answer
I just find out that MonoBehaviors with default parameters aren't allowed if the class is declared inside a namespace. Don't know if it is a bug. – Heisenbug Oct 10 '13 at 16:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.