dacha
    Preparing search index...

    Class Component<C>Abstract

    Base class for all components.

    A component stores data for an actor. Extend this class to write your own component, and name it with DefineComponent. The engine uses the name to find the class for a component in the configuration. A class without the decorator can set a static componentName instead.

    @DefineComponent({ name: 'Health' })
    class Health extends Component {
    @DefineField({ initialValue: 100 })
    points!: number;
    }

    Type Parameters

    • C extends object = object

      The type of the configuration passed to the constructor.

    Hierarchy (View Summary)

    Index
    • Creates the component.

      Type Parameters

      • C extends object = object

        The type of the configuration passed to the constructor.

      Parameters

      • Optionalconfig: C

        The component's configuration. Fields marked with DefineField take their values from config, or its decorated fields keep their initial values.

      Returns Component<C>

    actor?: Actor

    The actor that has this component. It is undefined until the component is added to an actor.

    componentName: string

    The name the configuration uses for the component. It must be unique among the components of the game.

    DefineComponent sets it, so a game usually does not assign it.

    • Returns the component of the same class on the parent actor.

      Returns Component<object> | undefined

      The component, or undefined if the actor has no parent actor or the parent has no such component.