gameObject.GetComponent("Script").enabled = true not working

Hi all,

I have created a script that controls Motion Blur image effect but “gameObject.GetComponent(“Script”).enabled = true;” not working, it says “BCE0019: ‘enabled’ is not a member of ‘UnityEngine.Component’.”

Thanks in advance for help :wink:

Edit → Unity 5 : GetComponent(“ScriptName”) is deprecated (the string version). You must use one of the other versions.

Once again. NEVER use the string-based version of the method GetComponent which returns a Component (the compiler cannot infer the type). Instead, use the type-based method:

// JS
gameObject.GetComponent( Script ).enabled = true;

// C#
gameObject.GetComponent<Script>().enabled = true;
// or
(gameObject.GetComponent( typeof(Script) ) as Script).enabled = true;

or you could do (gameObject.GetComponent( "Script" ) as MonoBehaviour).enabled = true;

I think it has to be:


If that doesn’t work try making a variable out of the GameObject the script is attached to.
or try GetComponent("Script"//or just Script).active

You probably don’t want that because it will disable the hole gameObject rather than just the component.

camera.main.gameObject.GetComponent(MouseOrbit).enabled = true ;

I had to use this > to access the First Person Controller component …

	gameObject.GetComponent(UnityStandardAssets.Characters.FirstPerson.FirstPersonController).enabled = false;