ComponentManager.create() method

create a new component of the given type. You can pass additional data that will be used to initialize the component.

Signature:

create<T extends CType>(data: CreateComponentArg<T>, opts?: {
        abort?: AbortSignal;
        transient?: boolean;
        parent?: Object3D;
    }): Promise<ComponentTypeMap[T]>;

Parameters

ParameterTypeDescription
dataCreateComponentArg<T>
opts{ abort?: AbortSignal; transient?: boolean; parent?: Object3D; }(Optional)

Returns:

Promise<ComponentTypeMap[T]>

a promise that resolves to the created component. The type of the returned component depends on the type of the component you created. For example a "model" component will return a ModelComponent.

Example

 const component = await Components.create({
     type: "model",
     url: "https://example.com/model.glb",
     position: { x: 0, y: 0, z: 0 }
     rotation: { x: 0, y: 0, z: 0 }
     scale: { x: 1, y: 1, z: 1 }
 })

For the data format, see the documentation of the component you want to create.