Script Working In Isolation, But Not After Changing Scene

Hey guys,

I have a scene which works absolutely fine when I run it directly in the editor. However, when I run it from what is the “control panel” in my game, the first person movement script in the scene doesn’t take any WASD commands. The mouse works fine, but I cannot move the player. Only happens when I switch scene from another one that has WASD controls to do different things.

The starting scene is https://launch.playcanvas.com/992466?debug=true. To reproduce the error, press P, and then the Back To Control Panel option. Once in the control panel, use the arrow keys to select the option “Go to refining bridge” on the screen directly in front of the camera. There, the script should allow the person to move freely using WASD, but this does not happen. The screen recording below shows the same.
https://www.dropbox.com/s/pieloip0nwx5rn6/e7272265-e7cd-4384-896f-122ac32ba1f4.mp4?dl=0

However, if I run the refining bridge scene on it’s own, it works fine - https://launch.playcanvas.com/989324?debug=true.

From the scene changing tutorial, I understand that the old hierarchy is destroyed. In this case, why is this happening, and how do I resolve it?

This code editor link has all relevant scripts open - https://playcanvas.com/editor/code/719288?tabs=35577599,37307297,37155761,35593864

In order - The Fly.js script is the script in the starting flight scene. The btcp.js script changes the scene to the control panel from the pause menu. The cycle.js script changes the scene to the refinery(lines 233-241 only), and the first-person-movement.js script is self explanatory.

How should I proceed?

Is there a way to solve this? Since I have enabled the required methods, could this be a bug in the scene changing script?

Hi @DevilZ,

I’ve tried following your steps to reproduce the error, but as soon as I go back to the control panel I get this error:

I can still select the refining room, indeed keyboard keys don’t work to move around. Now scene changing is an additive operation, it won’t replace or automatically delete the old hierarchy unless you explicitly do so.

What I’d check is when removing the old hierarchy if any script adding input handlers is properly removing them (using the .off() event call), when destroyed.

Hi @Leonidas,

Thanks for the reply. That error which you got isn’t related to this problem, it appears since that feature is still WIP. As you can see, there aren’t any explicit event listeners in the fly.js script, so why would it happen? I’m not sure what event it is, I’m aware that is an issue, but I haven’t declared any event in the past two scenes, the first event comes up in the first person movement script.