Change scene give errors

Yes i noticed, so i tagged all the entities on the levels scene and deleted them but the animation problem is still there… will try to create a small example but will not be an easy task

Side question, can i check if an animation exist and if not load it?

Get asset, then:

// check if asset resource is not available
if (! asset.resource) {
    // subscribe to loaded event
    asset.once('load', function() {
        console.log('asset loaded');
    });
    // start loading asset
    this.app.assets.load(asset);
}

have created a more simple version of the project here https://playcanvas.com/editor/scene/470471 if u need it more simple let me know…You have to launch levels scene and click on stairs to load the first scene then you get the error

It is very hard to narrow down the issue when there is so much in project.
Best way is to create simple project from scratch that only replicates the problem and no more. We as developers do this all the time to debug issues, but it would be very helpful if users would help us to help them. End of the day we have to prioritise loads of work, and spending time on doing something that you have way more context information to do, might prove challenging for us.

So please, create empty project, and only do things to replicate issue, do not copy-paste code please, re-write only things that are required to narrow down the issue.

OK will try to build it from scratch…

1 Like

Since building it up from scratch is not possible atm (i don’t know where i have saved the player fbx files) so i cleaned all that i could. I have manteined the entity with animations coz it’s that the issue and have removed all others script. Just kept game.js script in Root coz it contains the code for change scene. If this is still too complex i will look for another solution.
PS: i know that simple things are fastest to check and you have lot of work to do, so i don’t blame you at all guys, you are always very helpful, it’s just that movement is the issue so need some file to replicate it
PPS: erased all the unuseful scripts from the priject

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.

1 Like

@Steven wow! seems that fixed the problem coz i don’t have anymore the error. Thanks a lot you have made my day brighter

Awesome stuff! :slight_smile:

Look forward to seeing the progress of the project!

Take a look here @steven https://playcanvas.com/editor/scene/468192 i hope to publish something more in november

1 Like

Hello again,just my thought, but if one use multiple scenes is better to not use the root element to put the scripts you can do that just if all the scripts in root are used in all scenes, since when u delete the entites u have to keep the root and that can cause some problem if one script is used just in 1 scene. Am i wrong?

I’m not 100% sure I understand your question.

From the sounds of it, it depends on the script. E.g If you create script which continuously rotates an object, that’s fine to be placed in a scene on the object that it is rotating as it doesn’t depend on anything else nor does anything else depend on it beyond the entity that it is attached to.

The problem comes when you have references to scripts/objects in scenes that get unloaded/deleted. You need to consider how your game deals with this scenario. Whether this will be changing the way the objects interact with each other or keeping track what is loaded and unloaded, it is a scenario you will have to deal with in open world style games.

Well i think i have dealed with the scripts that must or must not interact with different scenes, i have 1 more question, and i hope is the last i have a value depth in my script levels in root entity that must keep track of the player position in the dungeon, but if i change scene that value is kept or is resetted?

I don’t think it would change unless something in the project (another script, event, function call, etc) is causing it to

I have tried this a variable called base in Game.js placed in root, i change it from true to false when changing scene, in i print it with console.log when the new scene start it tell me true again…should i try a global variable?

Do you unload any scenes?

i just delete the entities in the scene i don’t need but i keep the root

Is there anywhere else in the code where that variable could be changed to true?

Hi @steven,

I seem to be facing a similar problem. However, I don’t exactly follow the callstack bit. Could you please explain that?