> For the complete documentation index, see [llms.txt](https://docs.multiset.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.multiset.ai/webxr-sdk/api-reference/mapanchor.md).

# MapAnchor

```typescript
import { MapAnchor } from '@multisetai/vps/needle';
```

A Needle Engine `Behaviour` that applies VPS localization to a GameObject. After a successful localization, it transforms the object to the correct world position using the map-to-world matrix. `MapAnchor` is detected and wired automatically by `MultisetVPS` at startup.

### Inspector Fields

| Field                | Type            | Default        | Description                                                                                                                                         |
| -------------------- | --------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `offset`             | `THREE.Vector3` | `(0, 0, 0)`    | Position offset from the map origin in metres                                                                                                       |
| `matchOrientation`   | `boolean`       | `true`         | Align the object's rotation to the map orientation                                                                                                  |
| `rotationOffset`     | `THREE.Euler`   | `(0°, 0°, 0°)` | Additional rotation applied after `matchOrientation`. Only takes effect when `matchOrientation` is `true`.                                          |
| `hideUntilLocalized` | `boolean`       | `true`         | Keep the object invisible until the first successful localization and re-hide it when the session ends                                              |
| `isRightHanded`      | `boolean`       | `false`        | Set `true` if entering Three.js (right-handed) coordinates. Leave `false` for Unity (left-handed) coordinates — `MapAnchor` converts automatically. |

### Coordinate Handedness

Needle Engine uses Three.js coordinates (right-handed, Y-up). Unity uses a left-handed coordinate system. `MapAnchor` converts automatically when `isRightHanded` is `false`:

* The X component of `offset` is negated
* The Y and Z components of `rotationOffset` are negated

Set `isRightHanded: true` only if you are entering coordinates from a Three.js source (such as a previous localization result).

### Hiding Behavior

When `hideUntilLocalized` is `true`, the entire GameObject is hidden until the first localization. Because Needle Engine skips `start()` on invisible GameObjects, any sibling component that must run before localization should be placed on a separate always-visible GameObject.

### Public Methods

| Method                                                                           | Description                                                                                                                  |
| -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `connectAdapter(adapter: NeedleAdapter)`                                         | Wire this anchor to an adapter. Called automatically by `MultisetVPS` for scene-placed anchors. Safe to call multiple times. |
| `applyLocalization(result: ILocalizeAndMapDetails, worldFromMap: THREE.Matrix4)` | Apply a localization result directly. Useful for testing or replaying a saved result.                                        |

### Needle Lifecycle

| Method        | Called when                                              |
| ------------- | -------------------------------------------------------- |
| `awake()`     | Sets `visible = false` if `hideUntilLocalized` is `true` |
| `onDestroy()` | Removes all registered listeners to prevent memory leaks |

### Runtime Instantiation

When a `MapAnchor` is instantiated at runtime (after `MultisetVPS.start()` has already run), call `registerAnchor` on the adapter to wire it up:

```typescript
import { instantiate } from '@needle-tools/engine';
import { MapAnchor } from '@multisetai/vps/needle';

const instance = instantiate(myPrefab);
const anchor = instance.getComponent(MapAnchor);

if (anchor && vps.adapter) {
  vps.adapter.registerAnchor(anchor);
  // If a localization already happened, the anchor is positioned immediately
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.multiset.ai/webxr-sdk/api-reference/mapanchor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
