whenever i switch scenes and try to shoot it tells me screen to world is undefined
you helped me with the code i hope you can help me with this.
Most likely your camera entity is destroyed when changing scenes. Can you post some code and/or a sample project to take a look?
Or that you haven’t removed mouse input listeners when the scene is destroyed.
here how about you have a look https://playcanvas.com/editor/scene/1061687
Just had a quick look and it’s the issue I mentioned before. You have event listeners that don’t unsubscribe when the entity is destroyed so you have dangling event callbacks.
Refer to this and similar threads about this Change scene give errors
@yaustar i had a look at the link you sent but an image was missing and i couldn’t make sense of it.
In your project, there are scripts that are listening to global events such as mouse input but are not unsubscribing when the script or the entity is destroyed.
When you change scene, the app still has these old event listeners for mouse events and the functions are still being called but as the script and entities are destroyed, there’s no data to act on.
Here is an example of mouse input in the Model Starter Kit project where you can see it adds a destroy event listener and removes the subscription to the mouse events.
This is what you need to do in your app where it’s listening to global events like the mouse, touch etc.
Looking at your project, this will need to be done on the firstpersonmovement, powpow and kuddy scripts.
if i made the camera a variable would that fix it?
var entity = this.app.root.findByName(“Camera”);
It won’t solve the root problem, no
i tried it while i was waiting for a response and i fixed it
It’s solves the symptom of the problem but now you have multiple callbacks being called when you press down on the mouse buttons.
The real fix is to unsubscribe to the event on the script destroy event as shown in my previous reply.