# Predicted View Attachment

`PredictedViewAttachment` pins the graphics of one predicted object to a point in another object's view, such as a hand bone or an `ItemHold` transform under a player's graphics. It is visual only: the simulation, its state and its physics never see it.

Use it when something should look attached to an interpolated or animated part of another body. Parenting a predicted object under another object's graphics does not work, because graphics are the interpolated view and the simulation must never depend on them.

***

**Setup**

Add the component next to a [`PredictedTransform`](https://purrnet.dev/docs/client-side-prediction/built-in-components/predicted-transform) that has a **Graphics** transform assigned.

* **Anchor**: the transform the graphics follow. Leave it empty to start detached.
* **Position Offset**: where the graphics sit in the anchor's rotation frame.
* **Rotation Offset**: the graphics rotation relative to the anchor.

***

**Usage**

Attach and detach from view code, based on state you already simulate:

```csharp
public class HeldItem : PredictedIdentity<HeldItemState>
{
    [SerializeField] private PredictedViewAttachment _attachment;

    protected override void UpdateView(HeldItemState viewState, HeldItemState? verified)
    {
        if (viewState.holder.HasValue &&
            predictionManager.hierarchy.TryGetGameObject(viewState.holder, out var holder) &&
            holder.TryGetComponent(out PlayerView player))
        {
            if (_attachment.anchor != player.itemHold)
                _attachment.Attach(player.itemHold);
        }
        else if (_attachment.isAttached)
        {
            _attachment.Detach();
        }
    }
}
```

While attached, the `PredictedTransform` stops moving its graphics (`updateGraphics` is off) and the component places them at the anchor every `LateUpdate`, after the Prediction Manager's view pass and after animation. `Detach()` hands the graphics back to interpolation on the next view update and restores whatever `updateGraphics` was before.

`Attach(anchor, position, rotation)` sets the offsets in the same call. `Apply()` places the graphics right away, for when something moves the anchor later in the frame (for example IK running after the component).

***

**Behavior Details**

* If the anchor is destroyed, for example because its owner despawned, the component detaches on its own.
* Disabling the component releases the graphics.
* Scale is ignored, matching view interpolation.
* Detaching snaps the graphics to the object's own interpolated pose. If the simulated body should travel with its holder too, also add a [`PredictedParent`](https://purrnet.dev/docs/client-side-prediction/built-in-components/predicted-parent) and parent it from simulation code, so the two poses stay close and detaching does not jump.
