scene.activeCamera is always set to last camera in scene.activeCameras array

Hi there! I am working on a task that involves adding an extra camera to the scene and rendering its view on a separate viewport, like in this PG -

The issue I face here is that the last camera in the scene.activeCameras array is always set to scene.activeCamera, where I expect to find my main camera. (In the PG, the console log shows the active camera set when a pointerDown is executed on the scene) This is causing a lot of miscalculations in other functionalities since the unintended camera is found in scene.activeCamera.
Is this behaviour intended, that the scene.activeCamera always refers to the last camera in scene.activeCameras?

I tried out the following -
→ Explicitly setting scene.activeCamera to the required camera does not work. (I have added this scenario to the scene.onPointerDown event in the PG).

→ I am hesitant to use scene.activeCameras[0] instead of scene.activeCamera since the codebase I am working on is quite large, and there are a lot of references to scene.activeCamera.

→ The order of activeCameras affect the order in which the viewports are rendered so I cannot add the new camera to the beginning of the activeCameras array.

Is this a bug? If not, is there an alternate solution I could try out?

Thank you! :slight_smile:

When activeCameras are not empty, each frame renders the camera in activeCameras, and in the process, the program modifies the activeCameras sequentially. At this point, activeCamera can no longer be used as the main camera, you need to maintain the main camera yourself.

1 Like

Yes, it is expected. When there are several cameras, at render time, they are processed in a loop, and scene.activeCamera is set to each camera in turn. So, at the end of the loop, scene.activeCamera is the last camera of scene.activeCameras. As @xiehangyun said, you should not rely on scene.activeCamera but maintain your own main camera instead.


Ah okay. Thanks for the clarification! :slight_smile:

Okay understood! Thank you :slight_smile: