Detecting Scene-View Light Toggle

Hi all,

I’ve got a custom light. It’s implemented using Command Buffers. Now, it doesn’t turn off when I toggle the lighting in the scene view. In the scene view, at the top near the tab, you can toggle a few things On/Off. Scene view lighting says that:

So then, I tried a few things. I figured out a simple way to check if my light is rendering for the scene view camera. Inside OnWillRenderObject, this gets called for the scene camera. But the scene camera isn’t in the cameras returned by Camera.allCameras. So in my OnWillRenderObject function, I can do this check:

public void OnWillRenderObject()
{
    List<Camera> allCameras = new List<Camera>(Camera.allCameras);
    if (!allCameras.Contains(Camera.current))
    {   // If it's not in there, it's the scene camera
        RenderAreaLightForCamera(Camera.current);
    }
}

So I thought that if would have a light attached to it. And if I check if it’s enabled, like the tool tip said, then I could know if the toggle was on. Seemed straight forward. But this camera has no light component, and it also has no children. It has a Camera, a Transform, a Flare layer, and I think a GUI layer. Nothing useful.

So I can’t seem to figure out how to get this information. This is a call to the Unity devs, or the experienced editor-extenders I guess. How can I get this toggle? I want my custom lights to adhere to the same rules as built-in lights. I plan on uploading this to the asset store, and making them stable is all I’ve been doing recently.

Thanks,

  • David
SceneView.lastActiveSceneView.sceneLighting
1 Like