NOTE: I am not sure if this problem is local or not. please check on your machine if possible.
https://playcanvas.com/project/1027777/overview/idk-at-this-point
So, I have coded a main menu with a button that takes you to the main game. This is all working fine and well, and previous errors are no longer there. However, when the player dies, the scene is meant to switch. This happens, however the game crashes as soon as the next scene is loaded and makes it so i have to close not just the launched scene but also the code editor, the editor, and the project overview. Any idea why this is happening?
// this code was taken from a different project and is the code that crashes the game
//check if health is > 0, else send them to the main menu (add death ui later)
if (this.health <= 0) {
var oldHierarchy = this.app.root.findByName('Root');
this.loadScene (this.sceneId, function () {
// Once the new scene has been loaded, destroy the old one
oldHierarchy.destroy();
});
}
FirstPersonMovement.prototype.loadScene = function (id, callback) {
// Get the path to the scene
var url = id + ".json";
this.app.loadSceneSettings(id, function (err) {
if (!err) {
// success
} else {
// error
}
});
// Load the scenes entity hierarchy
this.app.loadSceneHierarchy(url, function (err, parent) {
if (!err) {
callback(parent);
} else {
console.error (err);
}
});
};
// this is the script attatched to the button that starts the game (working fine)
var Startbutton = pc.createScript('startbutton');
Startbutton.attributes.add("sceneId", {type: "string", default: "0", title: "Scene ID to Load"});
// initialize code called once per entity
Startbutton.prototype.initialize = function() {
// mouse events
this.entity.element.on('mouseenter', this.onEnter, this);
this.entity.element.on('mousedown', this.onPress, this);
this.entity.element.on('mouseup', this.onRelease, this);
this.entity.element.on('mouseleave', this.onLeave, this);
// touch events
this.entity.element.on('touchstart', this.onPress, this);
this.entity.element.on('touchend', this.onRelease, this);
};
Startbutton.prototype.onPress = function (event) {
var oldHierarchy = this.app.root.findByName ('Root');
// this.loadScene (loadSceneSettings, function () {
// // this.loadScene.loadSceneSettings(loadSceneSettings);
// // Once the new scene has been loaded, destroy the old one
// oldHierarchy.destroy ();
// });
//
// var oldHierarchy = this.app.root.findByName ('Root');
this.loadScene (this.sceneId, function () {
// Once the new scene has been loaded, destroy the old one
oldHierarchy.destroy ();
});
};
// update code called every frame
Startbutton.prototype.update = function(dt) {
};
Startbutton.prototype.loadScene = function (id, callback) {
// Get the path to the scene
var url = id + ".json";
// Load the scenes entity hierarchy
this.app.loadSceneHierarchy(url, function (err, parent) {
if (!err) {
callback(parent);
} else {
console.error (err);
}
});
};