so I have a Canvas with a Screen Space - Overlay setup and need to detect changes to the canvas (hence window) in order to rescale certain objects.
So, I figured that there has to be some event I can listen to. But until now, I did not find a way to find one.
Any help here would be appreciated.
You can utilise the
OnRectTransformDimensionsChange.html callback by attaching a script to the canvas (or any GameObject that has a
RectTransform), and add the following code:
private void OnRectTransformDimensionsChange()
// The RectTransform has changed!
You could either add this to the root Canvas, or to any GameObjects whose RectTransform will automatically scale with the screen, but need some extra tweaking such as repositioning children or adjusting text sizes.
Here’s the official documentation: https://docs.unity3d.com/ScriptReference/EventSystems.UIBehaviour.OnRectTransformDimensionsChange.html