Error upon Collision of Rigidbody

Hello!

I’m currently experiencing an error in my game. When my character collides into the dumpster asset (rigidbody) it should destroy the current scene and load the assigned scene, but there’s an error that says “Cannot read properties of null (reading ‘element’)” and “Uncaught TypeError: Cannot read properties of null (reading ‘destroy’)”. It’s weird because it was working a while ago.

I would highly appreciate if someone were to help me

Here’s the Link of my Game:
https://playcanvas.com/editor/scene/1720914

Thank you!

Hi @iscm!

First of all, I’m curious why you don’t use the new method to change your scene? You basically only need the line of code below.

this.app.scenes.changeScene('Some Scene Name');

The errors are probably related to the events you create. If you create an event .on you have to make sure you also remove the event .off, for example if you destroy the entity when you change the scene.

https://developer.playcanvas.com/en/user-manual/scripting/communication/

If your game has only one level, you can also consider using only a UI overlay instead of a separate scene. This will avoid the above problems.