HomeWeb Components API Reference - v0.17.0
    Preparing search index...

    Class ScriptInstanceElement

    The ScriptInstanceElement interface provides properties and methods for manipulating <pc-script-instance> elements. The ScriptInstanceElement interface also inherits the properties and methods of the AsyncElement interface.

    Script attributes can be supplied through two channels:

    • Per-property attributes: any non-reserved attribute on the element maps to the script attribute of the same name (kebab-case to camelCase, e.g. focus-pointfocusPoint). Values are parsed according to the type of the attribute's current value — initially the script's declared default (numbers, booleans, strings, Vec2/3/4, Color, Quat as Euler angles) — and the asset:/entity:/vec2:/vec3:/vec4:/color: prefixes may be used to be explicit.
    • The attributes JSON attribute: an object supporting nested structures and attribute names that collide with reserved HTML attribute names (e.g. title).

    When both specify the same attribute, the per-property attribute wins — at creation and whenever either channel changes at runtime. The element's own name and enabled attributes configure the element itself and are not script attributes.

    Changing name on a live element destroys the old-name script instance and creates the new-name one, re-applying both attribute channels to it.

    The element becomes ready once its script instance has been created by the parent <pc-script> element.

    scriptattributeschange - Fired when the script's attributes change. The detail carries the new attributes object. Bubbles.

    scriptenablechange - Fired when the script's enabled state changes. The detail carries the new enabled state. Bubbles.

    scriptnamechange - Fired when the script is renamed on a live element. The detail carries oldName and newName. Bubbles.

    Hierarchy (View Summary)

    Index
    • get closestApp(): AppElement | null

      The nearest ancestor <pc-app> element, or null if this element has no <pc-app> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns AppElement | null

      The closest app element, or null.

    • get closestEntity(): EntityBaseElement | null

      The nearest ancestor element that fronts an entity — <pc-entity>, <pc-model> or <pc-node> — or null if this element has no such ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns EntityBaseElement | null

      The closest entity-fronting element, or null.

    • get name(): string

      Gets the name of the script.

      Returns string

      The name.

    • set name(value: string): void

      Sets the name of the script to create. The name attribute is the single source of truth (it is what the parent <pc-script> element reads when creating the instance), so the property writes through to it — assigning before insertion works as expected:

      const script = document.createElement('pc-script-instance');
      script.name = 'rotate';
      scriptsElement.appendChild(script);
      await script.ready();

      Parameters

      • value: string

        The name.

      Returns void

    • get scriptAttributes(): Record<string, any>

      Gets the attributes of the script.

      Returns Record<string, any>

      The attributes of the script.

    • set scriptAttributes(value: Record<string, any>): void

      Sets the attributes of the script as an object. Values are converted with the same rules as the attributes attribute: asset:/entity: references and vec2:/vec3:/vec4:/ color: prefixed strings are resolved, and a plain numeric array is converted to the type of the attribute it targets when that attribute currently holds a Vec2, Vec3, Vec4 or Color.

      Parameters

      • value: Record<string, any>

        The attributes of the script.

      Returns void

    • Called when the element is fully initialized and ready. Subclasses should call this when they're ready. Resolves the ready promise and dispatches a bubbling, composed ready event. Signals at most once per readiness cycle: a repeat call before _resetReady has re-armed the promise does nothing.

      Returns void

    • Returns the ready promise to its pending state. Subclasses should call this when the resource their readiness announced is torn down (typically from disconnectedCallback), so that a later re-initialization can signal readiness again. Does nothing while the promise is still pending — an in-flight waiter carries over to the next readiness cycle rather than being stranded on a promise nothing will ever resolve.

      Returns void

    • Returns a promise that resolves with this element when it's ready. This is the low-level primitive underlying whenReady, which is the recommended way to wait for elements.

      Readiness tracks the element's current lifecycle: once a ready element is torn down (for example by removing it from the document), this returns a fresh promise that resolves when the element is next ready. A promise obtained earlier stays resolved — call this again after re-inserting an element rather than reusing a promise from before its removal.

      Returns Promise<ScriptInstanceElement>

      A promise that resolves with this element when it's ready.