Making Button Inactive


I’ve recently been working on a game that has a reset button. In my use case, the reset button fires a bunch of events and then is tweened off screen rather than just disappearing. The only issue with this is that the button remains active as its being moved off screen allowing the user to press it multiple times. In order to fix this I was hoping to do something like this (this is from a test project I made) :

var StartButton = pc.createScript('startButton');

// initialize code called once per entity
StartButton.prototype.initialize = function() {
    this.entity.element.on('touchend', function(){
        console.log("button press"); = false;
    }, this);
    this.entity.element.on('mousedown', function(){
        console.log("button press"); = false;
    }, this);

After this script is fired, the button does not become inactive and still responds to being clicked on by outputting the console log message. Why is this? Is anyone able to tell me why its not disabled? Here is a test project as well:

Hi @Jake_Johnson,

This is because the elementComponent is always active. If you want your game to respond to the active state of your button you will want to use this.entity.button.on() instead of this.entity.element.on()

Check out this relevant documentation:


Fantastic, thank you so much.

1 Like