[SOLVED] How to detect that current camera render target changed?

I need to do something special with the aspectRatio of the camera. So I want to set the aspectRatioMode to ASPECT_MANUAL and calculate the aspectRatio each time the rendertarget changes.
But how to detect this?

Hi @simmania,

The render target of a camera is undefined unless the developer specifically sets it. So normally you should be able to do this in your code.

If you don’t have for some reason control over that, you could override the camera component render target setter with your own code (e.g. fire an event each time the setter executes). Here is the relevant code:

I do not understand. I never set the render target sizes. It depends on the device the game is running on, isn’t it? My iPhone will use a much smaller target render size then my iPad or desktop. So I assume the render size is set by PlayCanvas. As well as the aspectRatio when set to automatic.

I assume this function:

frameUpdate(rt) {
        if (this.aspectRatioMode === ASPECT_AUTO) {
            this.aspectRatio = this.calculateAspectRatio(rt);
        }
    }

will be called at startup and when render target size changes.

I guess I could make my own CameraComponent class and override this function? But it would be simpeler if I could fire an event when target size changes.
I’m a beginner. And to subclass CameraComponent and use that in the Editor is something I don’t know how to do.

Ah I see, when you put render target at your post title I thought you were referring to the special renderTarget property any camera has.

If what you are asking is an event when the viewport size changes, there is this:
https://developer.playcanvas.com/api/pc.GraphicsDevice.html#event:resizecanvas

this.app.graphicsDevice.on('resizecanvas', function(){

}, this);