Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes RigidBody remove component #5803

Merged
merged 2 commits into from Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/framework/components/rigid-body/component.js
Expand Up @@ -503,8 +503,12 @@ class RigidBodyComponent extends Component {
}

if (shape) {
if (this._body)
this.system.onRemove(entity, this);
if (this._body) {
this.system.removeBody(this._body);
this.system.destroyBody(this._body);

this._body = null;
}

const mass = this._type === BODYTYPE_DYNAMIC ? this._mass : 0;

Expand Down
10 changes: 2 additions & 8 deletions src/framework/components/rigid-body/system.js
Expand Up @@ -332,7 +332,6 @@ class RigidBodyComponentSystem extends ComponentSystem {
this.frameCollisions = {};

this.on('beforeremove', this.onBeforeRemove, this);
this.on('remove', this.onRemove, this);
}

/**
Expand Down Expand Up @@ -433,14 +432,9 @@ class RigidBodyComponentSystem extends ComponentSystem {
if (component.enabled) {
component.enabled = false;
}
}

onRemove(entity, component) {
const body = component.body;
if (body) {
this.removeBody(body);
this.destroyBody(body);

if (component.body) {
this.destroyBody(component.body);
component.body = null;
}
}
Expand Down