> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Base Components

> Shared VR base scripts for interaction, teleport validation, and room-scale collision prevention.

**Folder:** `Assets/_MolcaSDK/_VR/Scripts/Base/`

This page covers the common base-layer scripts used by VR scenes:

* `MolcaInteractionBase.cs`
* `TeleportValidator.cs`
* `PlayerCollisionPrevention.cs`

## MolcaInteractionBase

**File:** `Assets/_MolcaSDK/_VR/Scripts/Base/MolcaInteractionBase.cs`\
**Namespace:** `MolcaSDK.VR`

Abstract interaction foundation for XR interactables. It:

* auto-binds `XRBaseInteractable` on the same GameObject (or uses assigned one),
* tracks `selectEntered` / `selectExited`,
* exposes `UpdateInteraction()` for derived classes,
* supports optional distance-based force release (`maxInteractionDistance`),
* registers itself to the reference system after `RuntimeManager` initialization.

This is the base class behind documented interaction scripts such as valve and knob handlers.

## TeleportValidator

**File:** `Assets/_MolcaSDK/_VR/Scripts/Base/TeleportValidator.cs`\
**Requires:** `XRRayInteractor`

`TeleportValidator` gates teleport validity while teleport mode is active:

* applies a configured `interactionMask` to the ray interactor,
* listens to active-ray changes via `OnRayInteractorChanged(IXRRayProvider)`,
* checks if controller is colliding near a blocked surface (`CheckSphere`),
* checks for obstruction between controller and player head (`SphereCast`),
* disables raycast mask (`0`) when invalid to prevent teleport.

### Inspector notes

* Wire `OnRayInteractorChanged` from your controller input manager event.
* Set `interactionMask` to geometry that should block invalid teleport traces.
* Tune `controllerCollisionRadius` conservatively (default `0.05`).

## PlayerCollisionPrevention

**File:** `Assets/_MolcaSDK/_VR/Scripts/Base/PlayerCollisionPrevention.cs`\
**Requires:** `CharacterController`

Helps prevent room-scale clipping into walls/props by checking overlap around the HMD position and nudging the XR origin away from collisions on XZ.

### Inspector notes

* Attach to XR Origin root.
* Set `interactionLayer` to obstacle layers (walls, furniture, props).
* Tune `playerCollisionRadius` based on headset/body clearance.

## Code

Example derived interaction from `MolcaInteractionBase`:

```csharp theme={null}
using MolcaSDK.VR;
using UnityEngine;

public class CustomDialInteraction : MolcaInteractionBase
{
    protected override void UpdateInteraction()
    {
        // Custom per-frame interaction logic while selected.
    }
}
```

## Troubleshooting

* **Derived interaction never updates** - Ensure the object has a valid `XRBaseInteractable` and is actually selected.
* **Unexpected force release** - `maxInteractionDistance` may be too small; set to `0` to disable distance checks.
* **Teleport still allowed in blocked pose** - verify `OnRayInteractorChanged` wiring and `interactionMask` layers.
* **Player jitter near obstacles** - lower `playerCollisionRadius` and confirm obstacle colliders are clean (no noisy overlaps).

## Related

* [Molca interaction base](/vr/interactions/molca-interaction-base)
* [Valve interaction](/vr/interactions/valve-interaction)
* [Knob interaction](/vr/interactions/knob-interaction)
* [VR locomotion](/vr/locomotion)
