Cannot enable entity after disable it

@saif
I have checked disable working fine. But after this.entity.enabled = false;
this.entity.enabled = true; is not working… So… Here is my code.

ps : I have tried some codes. And I found this.entity.enabled = true; work fine inside onCollision function. But not working inside .update function.

var Coin = pc.createScript('coin');
var regen = false;
var timer = 0;

// initialize code called once per entity
Coin.prototype.initialize = function() {
    var app = this.app;
    this.on('enable', function(){
        console.log("ENTITY ENABLED !!");
    }, this);
    
    this.on('disable', function(){
        console.log("ENTITY DISABLED !!");
    }, this);
    
    var playerInven = app.root.findByName('Player');
    this.pi = playerInven.script.playerInventory;
    this.entity.collision.on('collisionstart',this.onCollision,this);
};


Coin.prototype.onCollision = function (result) {
    if(result.other.name ==='Player'){
        this.pi.GetCoin(2);
        this.entity.enabled = false;
        regen = true;
    }
};

Coin.prototype.update = function (dt) {
    if(regen) {
        this.entity.enabled = true;
        regen = false;
    }
};
// update code called every frame

2 posts were merged into an existing topic: How to make entity disappear and showup again?