Destroying moving body causes exception and breaks the game
Version
- Phaser Version: Phaser v3.60.0-beta.17
- Operating system: Windows 10
Description:
While player is moving i initiate destroy on the object or scene then this error happens I have put checks in place but as it is async codebase this error comes often
It's a simple fix to add if statement.
Why are you using Beta 17? (or was that just a mistake when opening the issue)
Also, I need to see some code for this. Simply destroying a Body isn't enough to trigger this error. There must be something else going on.
Sorry for the late response i fixed the issue
I changed to the latest version as well and it was happening again. After that i realized that maybe im using the destruction of the body wrong. You can see the commented line. That was causing the error (but not aways for some reason)
if (this.physicsBody) {
this.scene.matter.world.remove(this.physicsBody)
// this.physicsBody?.body?.gameObject?.destroy()
this.physicsBody = undefined
}
You can close this issue if you think it's ok
Edit: this.physicsBody is
this.physicsBody = this.scene.matter.add.image(this.x, this.y, "empty", undefined, {
mass: 100,
label: "character"
})
this.physicsBody.setBody({
type: 'circle',
radius: this.bodyRadius || 32
})
Thanks for updating your issue👍