When I press the reset button on my simple function, I expect to see the FIRST console.log in the console right away, displaying an array with 5 objects. After 5 seconds, the SECOND console.log should be displayed with an empty array. Everything seems to work fine in this scenario.
However, if I press the reset function but do not open the FIRST console.log in the console, then wait 5 seconds before opening both the FIRST and SECOND console.logs, I notice that both of them display empty arrays. This behavior raises the question of why this is happening.
reset: () => {
console.log("FIRST", world.bodies)
setTimeout(() => {
for (let i = 0; i < objectBoxToUpdate.length; i++) {
const rigidBody = objectBoxToUpdate[i].rigidBodyBox
world.removeRigidBody(rigidBody)
}
console.log("SECOND", world.bodies)
}, 5000)
}