Note: This project is using the legacy script system
In a nutshell, in the player.js script, you subscribe the mouse down event which in turn performs a raycast and calls the moveTo function if the raycast hits an object. The problem occurs because you destroy the player entity but don’t unsubscribe from the mouseDown event and therefore the callback to the function still exists but other associated objects have been destroyed (like the model).
So what you need to do to fix this particular problem is to create a destroy function (which gets calls automatically when the component instance is destroyed or removed from the entity) which unsubscribes the mouse down event.
destroy: function () {
app.mouse.off("mousedown", this.onMouseDown, this);
},
What really helps when you run into issues like this is to open the Developer Tools panel in Chrome and switch to the sources tab as it will stop at the line of code that is causing the exception:
And then you can investigate the callstack to work out what could be causing the issue:
I still think you have some issues with loading levels in general as I get a grey screen after I unsubscribe to the mousedown event but hopefully fixing this will get you part way there.