Hide a light for a camera

Hi everyone!

I wanted to know if it is possible to hide a light for a camera?

I tried to use layers:
I assign a layer for my light, and in my camera inspector, I cull the mask linked to my light, but I can still see my light through my camera.
The idea is to see the world though camera 1 with the light, but through camera 2 without this light.

So I wonder if I misused the layers, or if there is another method.

Thanks in advance!

I did a quick setup, and what you describe works fine for me. Make sure the Culling Mask property is correctly set for the light. Make sure the object you want to light are on the correct layers also.

2 Answers

2

I am not sure if Wolfram’s answer was working by itself in previous versions of Unity, but 4.6 seems to require a slightly different setup. For anyone that stumbles across this like I did, this is what was needed in the script attached to the camera that does NOT see the light. It did not work until OnPreCull was added, but OnPreRender has been left as a precaution.

function OnPreCull () {
	if (limelight != null)
		limelight.enabled = false;
}

function OnPreRender() {
	if (limelight != null)
		limelight.enabled = false;
}

function OnPostRender() {
	if (limelight != null)
		limelight.enabled = true;
}

That works perfectly, thank you

Works! 2017.1

Hi. Can you tell me what is limelight? i searched it but i can't find that word in unity. i tried copying your code to my C# script and just changed the "function" to "void".. limelight is colored red and says the word doesn't exist in the current context. I am making a minimap with my horror game and it has flashlight in it but yeah my minimap cam still can see the light x_x

As I see in docs, you should not change anything. It should work with provided example. Does it not?

Hm, you should be able to do this with OnPreRender and OnPostRender. Attach a script with these functions to Camera2, and in OnPreRender disable the light, and in OnPostRender re-enable it.

Thank you, it's exactly what I wanted!