# NodeElement

Class · extends [`EntityBaseElement`](https://api.playcanvas.com/web-components/classes/EntityBaseElement.md) · category: Entities

Source: https://github.com/playcanvas/web-components/blob/252f001881302c266c8d727044408c32be2bb5e7/src/node.ts#L233

The NodeElement interface provides properties and methods for manipulating
[`<pc-node>`](https://developer.playcanvas.com/user-manual/web-components/tags/pc-node/)
elements. The NodeElement interface also inherits the properties and methods of the
[HTMLElement](https://developer.mozilla.org/docs/Web/API/HTMLElement) interface.

A `pc-node` is an override element: where `pc-entity` creates an entity, `pc-node` binds to a
node a `pc-model` loaded and declares overrides against the authored asset — components to
add, properties to change, content to attach. Attributes present apply as overrides; attributes
absent leave authored values untouched, and removing an attribute (or assigning `null` to the
matching property) restores the authored value.

`name` selects among the host model's nodes (first match in depth-first order), nesting a
`pc-node` inside another scopes the search to that subtree, and `index` picks among identically
named matches. When `name` matches more than one node and no `index` is given, the element
warns and binds nothing.

The element becomes ready once bound, and never while unresolved — a missing or ambiguous
name warns and records the failure in `state`, readiness stays unresolved, and descendants
wait with it.

The pointer events below are dispatched by the containing `<pc-app>` element when the pointer
is over the bound node's geometry, exactly as for `<pc-entity>`. Like every DOM event they
propagate through the element tree, not through the model's node hierarchy: a hit below the
bound node reaches this element when no nearer `pc-node` fronts it, or when the `pc-node` that
does is nested inside this one.

**elementSummary** The `<pc-node>` element binds to a node inside the hierarchy a `<pc-model>`
instantiated and declares overrides against it: a transform, an enabled state, tags, components
to add, or content to attach. Its `name` is a lookup, never a rename. Must be a descendant of
`<pc-model>`.

**attribute** name - The name of the node to bind, resolved within the nearest ancestor
`pc-model` (or `pc-node`) once it has instantiated.

**attribute** index - Which match to bind when `name` matches more than one node,
0-based in depth-first order. Optional for a unique match; required for an ambiguous one.

**attribute** enabled - Overrides the node's enabled state.

**attribute** position - Overrides the node's local position, as an "x y z" triple.

**attribute** rotation - Overrides the node's local rotation (Euler angles), as an
"x y z" triple.

**attribute** scale - Overrides the node's local scale, as an "x y z" triple.

**attribute** tags - Overrides the node's tags, separated by spaces or commas.

**attribute** material-overrides - Overrides material assignments on the bound node's
render component, as a JSON object from selector to `pc-material` id — for example
`{"name:CarPaint": "candy-red", "index:7": "smoked-glass"}`. A `name:X` key selects every mesh
instance whose baseline material is named `X`; an `index:N` key selects mesh instance `N` and
wins over a name rule for the same instance. Assignments no rule matches keep their baseline
materials, and removing the attribute restores all of them. Use `pc-model.hierarchy()` to
discover the names and indices a node offers.

**attribute** onpointerover - Script to run when the pointer moves onto the node, or onto
an entity below it.

**attribute** onpointerenter - Script to run when the pointer moves onto the node or an
entity below it, having been over none of them.

**attribute** onpointermove - Script to run when the pointer moves over the node.

**attribute** onpointerdown - Script to run when a pointer button is pressed over the node.

**attribute** onpointerup - Script to run when a pointer button is released over the node.

**attribute** onpointercancel - Script to run when the browser cancels a press that began
over the node, for example because a touch became a scroll.

**attribute** onpointerout - Script to run when the pointer moves off the node, or off an
entity below it.

**attribute** onpointerleave - Script to run when the pointer moves off the node and every
entity below it.

**attribute** onclick - Script to run when the node is clicked: a primary pointer button
pressed and then released over it.

**fires** pointerover - Fired when the pointer moves onto the node. Bubbles;
`relatedTarget` is the element the pointer came from, which is `<pc-app>` when it came from the
background.

**fires** pointerenter - Fired when the pointer moves onto the node or an entity
below it, having been over none of them. Does not bubble.

**fires** pointermove - Fired when the pointer moves over the node.

**fires** pointerdown - Fired when a pointer button is pressed over the node.

**fires** pointerup - Fired when a pointer button is released over the node.

**fires** pointercancel - Fired on the node a press began over when the browser
cancels that press, for example because a touch became a scroll. No click follows.

**fires** pointerout - Fired when the pointer moves off the node. Bubbles;
`relatedTarget` is the element the pointer went to, which is `<pc-app>` when it went to the
background.

**fires** pointerleave - Fired when the pointer moves off the node and every entity
below it. Does not bubble.

**fires** click - Fired when a primary pointer button is pressed and then released
over the node. A press and release that picked different elements fires on their nearest common
ancestor instead, as in the DOM. `detail` carries the click count, so a double click arrives as a
click whose `detail` is 2.

## Accessors

### enabled

```ts
get enabled(): boolean | null
set enabled(value: boolean | null)
```

Gets the enabled override.

### index

```ts
get index(): number | null
set index(value: number | null)
```

Gets which match to bind.

### materialOverrides

```ts
get materialOverrides(): Readonly<Record<string, string>> | null
set materialOverrides(value: Readonly<Record<string, string>> | null)
```

Gets the material overrides.

### name

```ts
get name(): string
set name(value: string)
```

Gets the name of the node to bind.

### path

```ts
get path(): string | null
```

The path of the bound node below the search root, `/`-separated, or `null` while not
bound.

### position

```ts
get position(): Vec3 | null
set position(value: Vec3 | null)
```

Gets the local position override.

### rotation

```ts
get rotation(): Vec3 | null
set rotation(value: Vec3 | null)
```

Gets the local rotation override.

### scale

```ts
get scale(): Vec3 | null
set scale(value: Vec3 | null)
```

Gets the local scale override.

### state

```ts
get state(): NodeBindingState
```

The binding state: `pending` until the host instantiates and `name` resolves, `bound`
once decorated, `missing`/`ambiguous`/`duplicate` when resolution failed (each also
warns). Useful for asserting a document's bindings programmatically.

### tags

```ts
get tags(): string[] | null
set tags(value: string[] | null)
```

Gets the tags override.

## Inherited from [EntityBaseElement](https://api.playcanvas.com/web-components/classes/EntityBaseElement.md)

- `protected _appElement: AppElement | null = null`
- `get closestApp(): AppElement | null`
- `get closestEntity(): EntityBaseElement | null`
- `get entity(): Entity | null`
- `protected _onReady(): void`
- `protected _registerEntity(entity: Entity): void`
- `protected _resetReady(): void`
- `protected _unregisterEntity(entity: Entity): void`
- `ready(): Promise<NodeElement>`
