Hello,
I have only one scene “GamePlay”.
When i try to change Scene to “GamePlay” (actually game reloads which i want it to happen) I am getting error…
Error:
Uncaught TypeError: Cannot read property 'hitPadding' of null
at ButtonComponent.get (playcanvas-stable.dbg.js:28851)
at ElementInput._buildHitCorners (playcanvas-stable.dbg.js:56094)
at ElementInput._checkElement (playcanvas-stable.dbg.js:56179)
at ElementInput._getTargetElement (playcanvas-stable.dbg.js:56066)
at ElementInput._onElementMouseEvent (playcanvas-stable.dbg.js:55869)
at ElementInput._handleMove (playcanvas-stable.dbg.js:55754)
get @ playcanvas-stable.dbg.js:28851
_buildHitCorners @ playcanvas-stable.dbg.js:56094
_checkElement @ playcanvas-stable.dbg.js:56179
_getTargetElement @ playcanvas-stable.dbg.js:56066
_onElementMouseEvent @ playcanvas-stable.dbg.js:55869
_handleMove @ playcanvas-stable.dbg.js:55754
Here is button click Snippet
this.restartBtnCompEntity.element.on('click', function (evt) {
this.isGameStarted = false;
this.isGameOver = false;
// Change scenes in 10 ms
var self = this;
var sceneName = this.sceneManagerEntity.script.sceneManagerScript.sceneNames[0];
console.log(sceneName);
setTimeout(function(){
self.loadScene(sceneName); // reload game
}.bind(this),10);
}, this);
Here is my load scene function
/*******************************************************\
| Load Scene
\*******************************************************/
GamePlayManagerScript.prototype.loadScene = function (sceneName) {
// Get a reference to the scene's root object
var oldHierarchy = this.app.root.findByName ('Root');
// Get the path to the scene
var scene = this.app.scenes.find(sceneName);
// Load the scenes entity hierarchy
this.app.scenes.loadSceneHierarchy(scene.url, function (err, parent) {
if (!err) {
oldHierarchy.destroy();
} else {
console.error(err);
}
});
};
How i can fix this?