[SOLVED] app.loadSceneHierarchy seems to be broken

It has, but this.app.root works since scene were destroyed and now I really get errors only about rigidbody.

So, it there a bug in Engine, you think? Probably temporary workaround?..

I need to make the repo case to be sure and send to the team on GitHub unless someone from the team gets there first.

I just tested it by

image

So… I don’t know.

What if I get script component init before rigidbody was created?..

Edit: Ignore this post. I made a mistake in the repo

I just tested my theory- rigidbody really appears after script component initialization. So, everywhere in my code I have to check is rigidbody exists.

Probably we need some priority for components?.. And scripts should be initialized last of all?

Ooooh… Now I see where I’m going wrong. Sorry @mikefinch, now I realise what you are trying to say. It looks like the hierarchy is destroyed AFTER the new scene hierarchy is loaded hence all findByName are finding the old scene references and that you are trying to get around this by using this.app.scene.root

Yes, according to tutorial.

But if I destroy it before loadSceneHierarchy, it’s okay.

oldHierarchy.destroy();   
this.app.loadSceneHierarchy("587372.json", function (err, parent) {          
});

Now I confused only by different behavior of scene loading.
I mean, if It loads by engine, when you open page, script component inits correctly, after all.
And we need the same behavior in loadSceneHierarchy, I guess.

Because now I can have no rigidbody in script, as I said before.

The thing is that at that point, the engine doesn’t have anything to destroy and there is no pre existing there’s no hierarchy in place so any findByName calls are fine.

I’ve got my fork working with no exceptions via your method of destroying the old hierarchy before the load and changing this.app.scene.root to this.app.root.

https://playcanvas.com/project/535191/overview/griper-drive-from-forums

The issue that you got was because it was destroying the entities and components in the middle of the update call so you were effectively doing:

this.entity.destroy(); // removes all the components etc
this.entity.rigidbody.applyTorque(); // no rigidbody as it was destroyed above

In a nutshell, you were getting exceptions from the ‘old’ player ship entity in the third scene and not the ‘new’ one.

I’ve just moved the oldHierarchy.destroy(); call to the end of the update function to prevent this.

Hm…
No, destroying entity removes its components.

Problem with creating components for new entities.
Now it gets right reference to another entity, but script component inits before rigidbody component.

So about one update loop I have no rigidbody.

I haven’t hit that problem in my fork? Can you try it out and see if you ran into the same issue?

Sure, in a few hours. Thanks a lot.

I finally figured this out. Oh, damn it.

So problem was with my update loop. You moved loadSceneHierarchy into update loop, at the end. But I placed in a middle. So my code keep working after scene was replaced, that’s why I got error about rigidbody.

Now it’s crystal clear.
What about removeChild? Do you now why it happened?

Hmm… Honestly no idea. I wonder if it was a red herring or I overlooked something (it was pretty light when I was looking at it :stuck_out_tongue: )