Open osyrisrblx opened 2 years ago
Constructors that yield are useful for setting up class members using functions like .WaitForChild(). The component will not setup any lifecycle events until the constructor is complete. This allows for patterns like:
.WaitForChild()
@Component({ tag: "CharacterComponent" }) export class CharacterComponent extends BaseComponent<{}, Model> implements OnPhysics { private humanoid: Humanoid; constructor() { super(); const humanoid = this.instance.WaitForChild("Humanoid", 5); assert(humanoid && humanoid.IsA("Humanoid")); this.humanoid = humanoid; } onPhysics() { // use this.humanoid } }
removeComponent would need to wait for the constructor to finish before calling destroy()
removeComponent
destroy()
Constructors that yield are useful for setting up class members using functions like
.WaitForChild()
. The component will not setup any lifecycle events until the constructor is complete. This allows for patterns like:removeComponent
would need to wait for the constructor to finish before callingdestroy()