# FitInsideCoplanarRectTransform(RectTransform, bool)

> Moves and optionally shrinks this RectTransform so that it fits inside the given coplanar RectTransform.

## Definition

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

```csharp
public RectTransform.FitResult FitInsideCoplanarRectTransform(RectTransform target, bool allowShrink = false)
```

### Parameters

**** (\[RectTransform]\(/engine/6000.7/script-reference/unityengine/recttransform)): The RectTransform to fit this RectTransform inside.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to scale this RectTransform down uniformly when it is larger than `target`. If false and the RectTransform doesn't fit, this method returns [RectTransform.FitResult.FailLargerThanTarget](/engine/6000.7/script-reference/unityengine/recttransform/fitresult/faillargerthantarget.md).

### Returns

| Type                                                                                | Description                                                                                                                                                        |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [FitResult](/engine/6000.7/script-reference/unityengine/recttransform/fitresult.md) | The result of fitting. Refer to [RectTransform.FitResult](/engine/6000.7/script-reference/unityengine/recttransform/fitresult.md) enumeration for possible values. |

### Remarks

When `allowShrink` is true and this RectTransform is too large to fit, this method uniformly reduces both axes of [RectTransform.sizeDelta](/engine/6000.7/script-reference/unityengine/recttransform/sizedelta.md) to preserve the aspect ratio before translating.

This method does not verify the target size, nor does it check whether the two RectTransforms are coplanar or share the same Z rotation. Use [RectTransform.TryFitInsideCoplanarRectTransform](/engine/6000.7/script-reference/unityengine/recttransform/tryfitinsidecoplanarrecttransform.md) to perform both checks.

Additional Resources: [RectTransform.TryFitInsideCoplanarRectTransform](/engine/6000.7/script-reference/unityengine/recttransform/tryfitinsidecoplanarrecttransform.md), [RectTransform.FitResult](/engine/6000.7/script-reference/unityengine/recttransform/fitresult.md).

### Examples

```csharp
//Attach this script to a tooltip panel that is a child of a screen-space canvas.
//When the button is clicked, the tooltip will attempt to fit inside the canvas at the button's position.
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.FitInsideCoplanarRectTransform(m_ScreenRectTransform, true);
    }
}
```
