[SOLVED] Why the exit button isn't working

Hi, i had a problem while trying to make an “exit” button here is the code that i wrote any help pls!

var Exit = pc.createScript('exit');

// initialize code called once per entity

Exit.prototype.initialize = function() {

    this.entity.button.on('click', function(event) {

        // Find the Scene Registry Item by the name of the scene

var sceneItem = this.app.scenes.find('Menu');

// Load the scene data with a callback when it has finished

this.app.scenes.loadSceneData(sceneItem, function (err, sceneItem) {

    if (err) {

        console.error(err);

    } else {

        // Destroy all children under application root to remove the current loaded scene hierarchy

        var rootChildren = this.app.root.children;

        while(rootChildren.length > 0) {

            rootChildren[0].destroy();

        }

        // loadSceneHierarchy and loadSceneSettings is now a synchronous function call as

        // the the scene data has been loaded

        this.app.scenes.loadSceneHierarchy(sceneItem);

        this.app.scenes.loadSceneSettings(sceneItem);

        // Optional: unload the scene data to free resources

        this.app.scenes.unloadSceneData(sceneItem);

    }

}.bind(this));

    }, this);

};

Hi @TheGiantNinja and welcome! What’s the problem exactly? Does anything happen when you click the button?

Hi @Albertos nothing happen when i click on the button that’s the poblem

Can you check if the entity has an element component and if ‘Use Input’ of the component is enabled?

Yes, it has the element component and “Use input” is enabled

Can you share a link of your project so someone can take a look?

1 Like

Sure!
https://playcanvas.com/project/948617/overview/rtbio

The button I checked is working as expected (on my mobile). So which scene and which entity do we have to check?

is it working? because it doesn’t work on my pc i tried it more than 5 times

Are we looking at the same button?

Yes, ig

How do you know if you don’t know which button I looked at? Please tell which button in which scene is not working for you.

it’s the exit button in the main scene

This button is indeed not working, but I don’t see anything wrong. Can you try to add console.log('check'); inside to click event, to see in the console of your browser if the button is working or not?

I checked your project on my laptop and your button is actually working. The only problem is the size of the element. It’s too small and therefore only the left part of the button works. I suggest to change the width of the element to for example 100 (instead of 32).

1 Like

Done, thx for helping!