ECS Framework API / EntityRef
Function: EntityRef()
EntityRef():
PropertyDecorator
Defined in: packages/core/src/ECS/Decorators/EntityRefDecorator.ts:57
Entity引用装饰器
标记Component属性为Entity引用,自动追踪引用关系。 当被引用的Entity销毁时,该属性会自动设为null。
Returns
PropertyDecorator
Example
typescript
class ParentComponent extends Component {
@EntityRef() parent: Entity | null = null;
}
const parent = scene.createEntity('Parent');
const child = scene.createEntity('Child');
const comp = child.addComponent(new ParentComponent());
comp.parent = parent;
parent.destroy(); // comp.parent 自动变为 null