gameatp
October 15, 2018, 10:45am
#1
// Script components overloaded destroy
myScript.prototype.destroy = function(name){
console.log('script destroy');
}
// Entity add script components
var newEntity = new pc.Entity();
newEntity.addComponent('script');
newEntity.script.create('myScript');
//Then entity calls destroy.
entity.destroy();
// results
'script destroy’does not print.
That is, the destroy method of myScript is not invoked.
DevilZ
October 15, 2018, 11:04am
#2
What do you mean by print? I can’t see any console.logs or alerts in your code
gameatp
October 15, 2018, 4:23pm
#3
That is, the destroy method of myScript is not invoked.
vaios
October 15, 2018, 4:25pm
#4
Hello - destroy
is the name of the event fired on the script when it’s destroyed. So you need to register your destroy method as an event callback like so:
initialize () {
this.on('destroy', this.destroy, this);
}
2 Likes
gameatp
October 16, 2018, 2:13am
#5
Thank you. I thought it was automatically invoked.
gameatp
October 16, 2018, 2:14am
#6
gameatp:
Hello - destroy
is the name of the event fired on the script when it’s destroyed. So you need to register your destroy method as an event callback like so:
initialize () {
this.on('destroy', this.destroy, this);
}
Thank you. I thought it was automatically invoked.