[SOLVED] Hiccups when destroying an Object with Light

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!

Interesting. Haven’t seen this before. It would be of great help, if you could make that sample project public, so someone from the team can look into it.

Edit:
I was able to reproduce it.
https://playcanvas.com/project/745476/overview/light-bug
I will file an issue to the github repo.

Edit2:

2 Likes

Done!
https://playcanvas.com/project/745559/overview/light-performance-test

1 Like

I’ve been able to reproduce even without collision involved.

Just by destroying objects with light after a delay. Available at the “Destroyers” scene in project

What seems to be the case is when the light is destroyed, it triggers a shader compilation, and when the WebGL’s method getShaderParameter gets called in postLink, it takes too long.

I’ll keep debugging

Hey thanks for this. Please read the comments here: