BCE0019: 'enabled' is not a member of 'UnityEngine.Component'. (After Flash Build)

UNRESOLVED

Hi there.

I have been using Unity for a little while and I am quite far through my game.

I have been Building and Testing my game without a problem for some time now.
But yesterday I attempted to Build my game as a Flash.swf file,

I started Building and it went 3/4 the way through then suddenly quit and I had ‘Game-Breaking’ compiler errors to do with my scripts.
I suddenly had the error:

"BCE0019: ‘enabled’ is not a member of ‘UnityEngine.Component’. "

My scripts are Javascripts and ‘enabled’ always worked as I have it on many scripts.

My main script is:

function Update () {

if(Input.GetKey("escape")) {
    //pause the game
    Time.timeScale = 0;
    //show the pause menu
    var script3 = GetComponent("PauseMenuScript"); 
    script3.enabled = true;
    //disable the cursor hiding script
    var script4 = GetComponent("HideCursorScript"); 
    script4.enabled = false; 
    //Mouse Look
    GetComponent("MouseLook").enabled = false;
    //Ambience
    GetComponent("AudioSource").enabled = false;
    
    
    }
}

For you to get an Idea.

Please Help.
Thanks

Please use code tags when posting code. As for the problem, never use strings in GetComponent; that makes it return Component instead of the correct type. (For that matter, don’t use strings in GetKey either; use the KeyCode enum. Strings are problematic and should be avoided if there’s an alternative.)

–Eric

Thank you, I put code tags.

I am pretty new to scripting to what do you suggest I do to change these strings?

Float?
Int?

– Corey

Just take off the quotations and they will work correctly.

  var script3 = GetComponent(PauseMenuScript);

Thank you. This works fine for all scripts but not for the components “MouseLook” and “AudioSource”

     //Mouse Look
    GetComponent(MouseLook).enabled = false;

I am getting the error code:

BCE0005: Unknown identifier: ‘MouseLook’.

I even tried

var script5 = GetComponent(MouseLook);
script5.enabled = false;

and with quotations

var script5 = GetComponent("MouseLook");
script5.enabled = false;

Still no luck. I think this code only works for Javascript and I do not know the code for C# Scripts.

If MouseLook is c#, place MouseLook.cs in the Plugins folder.

AudioSource has enabled property, but I’m almost sure you don’t want to use it. Instead of this use Stop() or Pause() method.

I have a similar problem. I have an entire, perfectly working compiling Unity project that runs in Desktop mode great. I want to see if I can make a Flash version of it. When I switch to the FlashPlayer mode I get TONS of compiler errors. Many of them are BCE0019 on GetComponet(“SomeScript”). I did use a lot of string literals, but when I change them to GetComponent(SomeScript) I get BCE0005 "Unknown Identifier: ‘SomeScript’. The weird thing is those scripts are in my Standard Assets folder, they’re on all the necessary GameObjects, and this all works perfectly in desktop mode. I have errors on every GetComponent(“SomeScript”) that’s in my script(s).

It’s been a while since I touched Unity Flash, but as I recall it requires scripts to be strictly typed, which is also a requirement for iOS. With a desktop build target, adding #pragma strict to the top of a script will also enforce the script to be strictly typed and generate those same warnings. Once that is in force and you get an error that ‘enabled’ is not in ‘Component’ you should go straight to the Scripting Reference and confirm that indeed, the page for GameObject says that GetComponent returns Component and the page for Component does not list an ‘enabled’ variable. But ‘enabled’ is defined in Behaviour, which is a subclass of Component and is inherited by all Components that you can enable/disable (like Lights), incluiding MonoBehavior and thus all scripts. The solution is to use the generic version of GetComponent as Eric mentioned, described here:

http://docs.unity3d.com/Documentation/Manual/GenericFunctions.html

Or just explicitly declare the type, like this:

var script:Behaviour = GetComponent("whatever");

Here I’m specifying the most general class that has the desired variable, enabled.

Or you could just write everything in C#.

Edit: Oh, yeah, and that Standard Assets thing is bug: Unity 3.5 standard assets bug - Questions & Answers - Unity Discussions