# RectTransform.FitResult

> Indicates the result of a RectTransform fit operation.

## Definition

* **Type:** Enum
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public enum RectTransform.FitResult
```

## Remarks

The FitResult enumeration identifies the outcome of [RectTransform.TryFitInsideCoplanarRectTransform](/engine/6000.7/script-reference/unityengine/recttransform/tryfitinsidecoplanarrecttransform.md) and [RectTransform.FitInsideCoplanarRectTransform](/engine/6000.7/script-reference/unityengine/recttransform/fitinsidecoplanarrecttransform.md). It contains the result of the fit operation, indicating whether it succeeded or failed, and if it failed, the reason for the failure.

## Examples

```csharp
using UnityEngine;
using UnityEngine.UI;

public class TooltipController : MonoBehaviour
{
    [SerializeField]
    RectTransform m_ScreenRectTransform;

    [SerializeField]
    Button m_Button;

    RectTransform m_TooltipRectTransform;

    void Awake()
    {
        m_TooltipRectTransform = GetComponent<RectTransform>();
        gameObject.SetActive(false);
        m_Button.onClick.AddListener(() => { ShowAt(m_Button.GetComponent<RectTransform>()); });
    }

    public void ShowAt(RectTransform anchor)
    {
        gameObject.SetActive(true);
        m_TooltipRectTransform.position = anchor.position;

        // Constrain the tooltip to the container.
        RectTransform.FitResult fitResult = m_TooltipRectTransform.TryFitInsideCoplanarRectTransform(m_ScreenRectTransform, true);
        switch (fitResult)
        {
            case RectTransform.FitResult.Success:
            case RectTransform.FitResult.AlreadyInside:
                Debug.Log("Tooltip fit inside container successfully.", this);
                break;
            case RectTransform.FitResult.FailInvalidSizeTarget:
                Debug.LogWarning("Target container has invalid size and cannot be fit inside.", this);
                break;
            case RectTransform.FitResult.FailLargerThanTarget:
                Debug.LogWarning("Tooltip is larger than container and cannot be shrunk to fit.", this);
                break;
            case RectTransform.FitResult.FailNotCoplanar:
                Debug.LogWarning("Tooltip and container are not on the same canvas plane.", this);
                break;
            case RectTransform.FitResult.FailZRotationMismatch:
                Debug.LogWarning("Tooltip and container have mismatched Z rotations.", this);
                break;
        }
    }
}
```

## Fields

| Value                                                                                                                 | Description                                                                                            |
| --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| [AlreadyInside](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/alreadyinside.md)                 | The RectTransform is already fully inside the target. No change is made.                               |
| [FailInvalidSizeTarget](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/failinvalidsizetarget.md) | The target RectTransform has a zero or negative width or height. No change is made.                    |
| [FailLargerThanTarget](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/faillargerthantarget.md)   | The RectTransform is too large to fit inside the target and `allowShrink` is false. No change is made. |
| [FailNotCoplanar](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/failnotcoplanar.md)             | The RectTransform is not coplanar with the target. No change is made.                                  |
| [FailZRotationMismatch](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/failzrotationmismatch.md) | The RectTransform and the target have different Z rotations. No change is made.                        |
| [Success](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/success.md)                             | The RectTransform is moved, shrunk, or both, to fit inside the target.                                 |
