Skip to content

ECS Framework API v2.2.13


ECS Framework API / requireComponent

Function: requireComponent()

requireComponent<T>(entity, componentType): ComponentInstance<T>

Defined in: packages/core/src/ECS/TypedEntity.ts:26

获取组件,如果不存在则抛出错误

Type Parameters

T

T extends ComponentConstructor

Parameters

entity

Entity

实体实例

componentType

T

组件类型构造函数

Returns

ComponentInstance<T>

组件实例(保证非空)

Throws

如果组件不存在

Example

typescript
const position = requireComponent(entity, Position);
position.x += 10;

Released under the MIT License.