[SOLVED] Cannot set properties after scene load


I am having difficulty loading a scene. I have a login page that once a person enters in a username and password that are both at least 8 characters long will then load the game play scene.

Link to login scene below.


When you click the ButtonL (Login and Play) within the scene after entering in a username and password the the script attached to the button should load the gameplay scene (Code that loads scene below, whole script here).

However, when I load the scene multiple entities are spawned and I get the following error

Cannot set properties of undefined (setting ‘x’)

x is the force applied to my sprite’s ridgidbody in the scene which is initialized in this script attached to the ‘ball’ entity within the game play scene.

It seems that a previous thread this issue had occurred but how it was resolved is not totally clear.

How can I have the x force of the entity initialized to prevent the error from being thrown and stop multiples of the ball entity from spawning.

I have modified the code here so that anyone who enters in a username and password that is at least 8 characters long can click the login and play button and replicate the error.


Fixed! See code below. I guess before I was loading the scene twice.

setTimeout(function() {
           if(go.responseText.split('\t',7)[0] == 0){
//destroy old scene
                 var old = this.app.root.findByName('Root');
//                   this.app.scenes.loadScene('1234829.json', function(){

//                 });
                //var sceneItem = this.app.scenes.find("Scene Name");
//Load new scene
             this.app.scenes.loadSceneHierarchy('1234829.json', function (err, entity) {
                    if (!err) {
                    } else {
        // error

        }.bind(this), 1000);