How to get screen size before the OnUpdate?

Hello, if we take/consider the following example: Camera to texture

I want to create GPUTexture based on screen size. For this I need to access Screen.Size.X/Y but I can’t access it even though I tried on OnAwake, OnStart and OnEnable. Engine crashes and shuts down. (probably it is return null or something.)

Any suggestion?

Edit: I can create the texture in OnUpdate as in the example below, but I don’t know if this is a safe way.

     public override void OnUpdate()
        {
            if (texture_is_initialized == false)
            {
                var desc = GPUTextureDescription.New2D((int)Screen.Size.X, (int)Screen.Size.Y, PixelFormat.R8G8B8A8_UNorm);
                _output.Init(ref desc);
                texture_is_initialized = true;
            }
            _task.Enabled = true;
        }

For upcoming update 1.4 we’ve fixed the Screen to not return invalid values in Editor if the viewport is not focused by the player so it should work fine on the new version.

1 Like