Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

RectTransformUtility.GetScreenRect

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static Rect GetScreenRect(RectTransform rectTransform);

Parameters

Parameter Description
rectTransform The RectTransform whose screen-space bounding box to compute.

Returns

Rect A Rect describing the screen-space bounding box in pixels. Width and height are always non-negative.

Description

Returns the screen-space axis-aligned bounding box of the given RectTransform.

The four world-space corners are projected to screen space using Camera.main. For Screen Space - Overlay canvases, the corners are already in screen-pixel coordinates and camera projection is skipped regardless of whether Camera.main is set, to avoid double-projecting them.

Note: This method uses Camera.main for camera projection. For canvases rendered by a specific non-main camera, use GetScreenRect(RectTransform,Camera) and pass the correct camera explicitly.

Additional resources: GetScreenRect(RectTransform,Camera).


Declaration

public static Rect GetScreenRect(RectTransform rectTransform, Camera camera);

Parameters

Parameter Description
rectTransform The RectTransform whose screen-space bounding box to compute.
camera The camera to use for world-to-screen projection. If null, or if the RectTransform belongs to a Screen Space - Overlay canvas, camera projection is skipped and the world corners are used directly as screen coordinates.

Returns

Rect A Rect describing the screen-space bounding box in pixels. Width and height are always non-negative.

Description

Returns the screen-space axis-aligned bounding box of the given RectTransform, using the specified camera for projection.

The four world-space corners are projected to screen space using the provided camera. For Screen Space - Overlay canvases, projection is skipped regardless of the camera argument to avoid double-projecting coordinates that are already in screen space.

Use the no-argument overload GetScreenRect(RectTransform) to project using Camera.main.

Additional resources: GetScreenRect(RectTransform).