- Home /
Question by
thereal_mpellegr · Nov 08, 2013 at 08:51 PM ·
bugcomponentsingletonrequirecomponent
Adding RequireComponent breaks script
After adding a RequireComponent directive to this script:
@script RequireComponent (Window)
class Menu extends MonoBehaviour{
private var window : Window;
function Start(){
window = GetComponent(Window);
}
function OnGUI(){
Main.INSTANCE.executeSomeFunction();
}
}
I can no longer access one of my singleton scripts. I get the error message: 'INSTANCE' is not a member of 'function(): void'.
. Here is the singleton class:
class Main extends MonoBehaviour{
static var INSTANCE : Main;
function Start(){
INSTANCE = FindObjectOfType(Main);
setState(initialState);
}
function OnApplicationQuit(){
INSTANCE = null;
}
}
Why is this happening?
Comment
"$$anonymous$$ain" is being interpreted as a function name. It's pretty close to the standard entry-point function name "main", maybe there's something going on there. Try changing the class name.
Changing the script to $$anonymous$$ainScript seems to have solved the issue. It's interesting how this error wasn't produced before using the RequireScript.
Best Answer
Answer by thereal_mpellegr · Nov 12, 2013 at 05:05 PM
Using Main as the scripts name was causing issues after adding the RequireComponent line.