Hello!
I’m having a problem when im calling this.entity.destroy
on an entity that has a light as a child.
Probably I’m doing this the wrong way or there must be a way to optimise this.
Here’s the thing, I have a Life Pickup that has a red light, a collision box, a sphere mode, the pickup script and a tween script.
On the Pickup script I just wait for trigger enter, then I check if the entity has the player script, if so call the add health on the player, then destroy itself.
Pickup.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
Pickup.prototype.onTriggerEnter = function(entity) {
if(entity.script && entity.script.player) {
entity.script.player.gainHealth(20);
this.entity.destroy();
}
};
And when I touch the pickups, each time there’s a little hiccup: (Click to open gif on giphy and see at 60fps)
I’ve already debugged the code and found out that it’s the light component that causes the delay, when I remove it or disable, the hiccups stop.
Its obvious that the destruction of the light is affecting the frame time, but I’ve run out of ideas of how to do this without removing the light from the object
Any heads up on this would help a ton, thanks!