- Home /
Duplicate Question
Weird Problem with optional function parameter
I am having the most weirdest problem. I have an empty game object on which i attach a script name Test.cs
I can not have any function with optional parameter within Test.cs. If I do it gives me the following error on the component tab "The associated script cannot be loaded. Please fix any complie errors and assign a valid script". But note that there is no error on the console. More interesting thing is, I have been testing different things and I found out that as long as I am in a namespace it causes this issue. If I am not in a namespace, it doesn't.
The following code works
using UnityEngine;
using System.Collections;
using Widgets;
public class Test : MonoBehaviour{
void foo(int index = 1)
{
}
}
However this does not work as I add the namespace
using UnityEngine;
using System.Collections;
using Widgets;
namespace Widgets {
public class Test : MonoBehaviour{
void foo(int index = 1)
{
}
}
}
And the following works since I remove the optional function parameter
using UnityEngine;
using System.Collections;
using Widgets;
namespace Widgets {
public class Test : MonoBehaviour{
void foo(int index)
{
}
}
}
This bizarre problem is driving me crazy. Please help
It appears to be an ongoing issue in unity. **Here** is a forum thread discussing it. At the moment it seems the only solution is to not use optional parameters. It is not really an answer though, so I did not put it as one.
Ah thanks for infor$$anonymous$$g. I thought I was the only one having this issue.