Target Indicators
Search Results for

    Show / Hide Table of Contents

    uGUI indicators

    A TargetIndicator is a C# struct containing screen-space data, not a visual element. To display this data, you must create your own visual indicator.

    Building visual indicators with Unity UI requires understanding the RectTransform system, specifically the relationship between a visual indicator's RectTransform and its parent's RectTransform.

    Visual Indicator Parent RectTransform

    The RectTransform of a visual indicator's parent significantly influences how indicators are positioned on the screen, particularly due to its anchors, size, and pivot.

    To ensure a target's ScreenPose.position directly corresponds to the anchoredPosition of a child visual indicator, the parent RectTransform should have its anchorMin set to (0, 0) and its anchorMax set to (1, 1). This configuration ensures the visual indicators reposition correctly regardless of the parent's pivot or size, and adapts to screen size changes.

    Visual Indicator RectTransform

    To position a visual indicator's RectTransform at a target's screen pose, assign the TargetIndicator.ScreenPose.position value to RectTransform.anchoredPosition.

    For the visual indicator to be perfectly centered on the target's screen pose, set its anchorMin, anchorMax, and pivot properties to (0.5, 0.5).

    If you need to offset a visual indicator from the target's precise screen pose, for example to place an arrow tip at the coordinate, create a child GameObject for the offset and parent the visual content to it. By applying the TargetIndicator.ScreenPose.position directly to the main visual indicator RectTransform, the desired offset will be maintained through the GameObject hierarchy.

    Canvas render mode

    For consistent and reliable results, use the Screen Space - Overlay Canvas Render Mode. This ensures visual indicators are always drawn on top of the 3D environment, preventing occlusion.

    If you use Screen Space - Camera and assign a camera, visual indicators can be occluded by scene geometry. This occurs if the Canvas's plane distance places it behind objects in the camera's view.

    Important

    Changing the CanvasScaler.uiScaleMode can alter the Canvas's scale, which affects how screen coordinates are interpreted.

    When applying TargetIndicator screen poses to your visual indicators, ensure you account for the Canvas's current scale. For instance, if the Canvas's scale factor is 0.5, you must double the TargetIndicator screen pose values to achieve correct placement.

    In this article
    Back to top Generated by DocFX