GetComponent problem

Hi,

I have this simple code to enable/disable an image effect but its returning null, I have the effect added to my camera and it is initially enabled but GetComponent and variants of fail to return a reference to it. It works fine on the SSAOEffect but not on the ColorCorrectionEffect either, any ideas what might be going on :face_with_spiral_eyes:

Thanks,

	if (funkyOn) 
		{
			cam.GetComponent<GlowEffect>().enabled=true;
		} 
		else
		{
			cam.GetComponent<GlowEffect>().enabled=false;
		}

What does the debugger say?
You can make the debugged sop unity on a null-reference exception, so you find what exactly is null and why.

Are you using Unityscript or c#? For unityscript GetComponent**.**() notice the period between GetComponent and < if you need a generic. See this page for good information on the different ways to get a component.

Hi,

I’m using c#, the debugger in MonoDevelop just throws a NullReference exception, the Unity console says the same thing, its just odd that its specific effects thats the problem…

Thanks.