onRemove method

  1. @override
void onRemove()
override

Called right before the component is removed from the game.

This method will only run for a component that was previously mounted into a component tree. If a component was never mounted (for example, when it is removed before it had a chance to mount), then this callback will not trigger. Thus, onRemove runs if and only if there was a corresponding onMount call before.

Implementation

@override
void onRemove() {
  if (_parentSizeListener != null) {
    hitboxParent.size.removeListener(_parentSizeListener!);
  }
  _transformAncestors.forEach((t) => t.removeListener(_transformListener));
  _collisionDetection?.remove(this);
  super.onRemove();
}