Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.