So this.player was null. I thought PlayCanvas appends all entities to scene’s root and then inits scripts. When primary scene is loading it seems to be that. But not by loadSceneHierarchy
What is a proper way to load my scene with assets, connected with other entities?
ALSO I just forked tutorial project and it has problem with assets too. I’m not sure it is the same sh… trouble, but I guess it’s better to be fixed?
When you fork that project, remember to update the scene ID attributes on the script attached to the camera. When you fork a scene, new scenes are created and the IDs change. But the attributes remain the same, because they’re ‘just text’.
Load project (scene third) and press Q to see exception in console.
Now It says that played doesn’t exist, but I think it’s the same problem.
if (this.app.keyboard.wasPressed(pc.KEY_Q)) {
var oldHierarchy = this.app.root.findByName('Root');
this.app.loadSceneHierarchy("587372.json", function (err, parent) {
oldHierarchy.destroy();
});
}
Looking at this as well. It looks like for some reason, the old hierarchy is not being destroyed during oldHierarchy.destroy(); but all the components have been destroyed. So in the new scene after the load, the magnet script is find the player entity that has no components from the previous scene.
Edit: Looking at this more, removeChild never actually executes this line: this._children.splice(i, 1); to remove the child from the parent.
I think there is a bug with entity.removeChild where the child is not actually being removed. I need to make a small repro case to be sure. (entity.destroy makes calls toentity.removeChild under the hood).
Take a look at loadSceneHierarchy function - it loads scene from url, parses it by pc.SceneParser.
Afterwards, it appends new root entity to pc.app.root and then should init components, like scripts, etc.
But, even If I remove this invocation, handler (pc.HierarchyHandler) inits it when creates.
I mean this line: var entity = handler.open(url, data);
Parses data, creates entities with components and inits them
So calling pc.ComponentSystem is unnecessary, since handler do the same. And it’s wrong, because my entities still are not appended to root.
So, in a nutshell, if you have no links to another entities into your prototype.initalize, it works fine, but if you do, you get an error about that, because it calls before entities were appended to scene.
The print out of the tree shows it still has entities from the third scene after the scene load but all the components have been removed so it will find the first player entity but it doesn’t have the rigidbody components etc.
this.app.scene.root.findByName("player");
Should also be:
this.app.root.findByName("player");
As far as I know, this.app.scene doesn’t have a root property.