Change level throws error

Hey guys, im trying to set up change level on finish from pc tutorial, but keep receivinng this error which is not coming out of my code

image


does anybody know where the issue might be? thanks

Hi @smokys,

That error is coming from the engine, a rigid body component complains about a missing body, most likely something isn’t destroyed properly.

Can you make sure that the oldHierarchy is found and deleted correctly before the error is thrown? If you continue getting the error try posting a sample project url to take a look.

You might also have an old reference to an entity that was destroyed.

1 Like

I tried to manualy set the scenes ID and it works, it seem that .url has a problem to get an ID from level. also when i delete root there are still the cloned objects in the new scene

image

The logic you have shown here is different to the what you posted in the first post irrespective of whether you are using the name or the id.

In the code where you are using the id, you are destroying the old scene immediately. Compared to your first post where it was destroyed after the new level is loaded.

I changed the logic the what it was before in first topic but it didnt make any difference:

in inspector i defined scenes ID

it also throwing error from script which should be deleted

Can you share your project please and how to reproduce this bug?

I was also struggling with changing the scene. Wasn’t really reproducible on a small scale but once there are a lot of scripts, effects and logic happening there always seem to be entitys that aren’t being deleted. But I am still investigating this one.

I used rather used loadScene because we had different scene settings.

I think this one https://playcanvas.com/project/733989/overview/race-run-3d
I dont know it is correct project or not, i am not sure about it.

Yup thats it

It’s a private project by the looks of things.

Yup it has to stay private as I cant realease the game code no longer

In which case, it’s very difficult to help without access to a reproducible, be it your main project or a smaller public one.

Is there a way I can copy entire game and paste in new project?

You can fork the project and remove bits that are not relevant. That’s probably your easiest bet.

And how can i fork the project? :slight_smile:

edit: found that

here is a link for the editor: https://playcanvas.com/editor/scene/1043429

you have to finish the loaded scene to see what happens in next level, it takes about 30 secs to finish :slight_smile:

also the script which contains change level function is called onFinishEnter.js

I still can’t access the Editor, is it marked as private?

1 Like

Yup sorry it was, its public now

// initialize code called once per entity
RollerSpawner.prototype.initialize = function() {
    
    //inicializacia casovaca spawneru
    this.timer = 0;
    this.waitTime = 2;
    
    //inicializacia objektov a pozicie miesta spawnu
    this.spawnPoint = this.app.root.findByName("SpawnPoint").getPosition();
    this.objectToSpawn = this.app.root.findByName("Roller");
    
setInterval(function(){
    
  var entity = this.app.root.findByName('Roller').clone();
  this.app.root.addChild(entity);
    this.objectToSpawn.rigidbody.teleport(this.spawnPoint);
    
}.bind(this),1500);
    
};

This is the problem. The setInterval needs to be cancelled/stopped when changing scenes.

What is happening here is the function is still being called every 1.5 secs and it’s referencing an entity that has had it’s data and components destroyed as part of loading the next scene.

ie

Your best bet here is to listen for the destroy event on this script and cancel the setInterval then.

1 Like