[SOLVED] Why is my game so laggy?

The jump script is making it happen, im 99% sure. I have no clue how or why. Let em look into some other jump scripts.

When I start the app and don’t interact at all with it, after a few minutes the drop in FPS still occurs.

Just a note to all: I will be opening a few new issue topics, but I will try my best to update my cure to the lag here when I find it!

I have the entities that need to despawn on this script:

var KillIfold = pc.createScript('killIfold');
KillIfold.attributes.add('oldAge',{type:"number"})
// initialize code called once per entity
KillIfold.prototype.initialize = function() {
  this.timer = 0;
    this.roundedTime = 0;
};

// update code called every frame
KillIfold.prototype.update = function(dt) {
    this.timer += dt;
 this.roundedTime = pc.math.roundUp(this.timer,1);
    if(this.roundedTime > this.oldAge){
this.entity.destroy();
    };
};

That keeps it under control for a while, for 100 seconds I think. After roughly 100 seconds, give or take a few, the entities start to spike.

I think destroy is destroying it visibly, but not actually, does anyone know how/why this would happen?

You’ve changed the code now since I forked it, but in the fork cloning the platform before populating it stopped the leak. Maybe this might help you with yout new code.

EndlessRunner.prototype.triggerenter = function (entity) {

        var newplatfrom = this.platform.clone();

        if (this.populater === true) {
            this.populate();
        };

Thanks. I will try that.
I did a quick test, and disable kept the FPS and entities lower than destroy.

I am not using populate function in that script anymore. It was too much of a pain. I moved it to its own script and it is now trigger on a fire event. Let me try moving the fire.

Also you might wanna delete the old fork and fork the project again, I’ve changed some things. Or if its easier I can add you.

I’ll fork again if I have the time.

1 Like

If you just keep cloning, disabling and holding on to resources, then you’ll run into problems. Better to destroy I think.

Let me make a quick graph to show the data

Nvm, the graph isnt working. From my data, destroy had worse FPS than Disable, but your code of putting fire last with disable did the best. Let me try your code with destroy.

Yeah, destroy does way worse tham disable.

If you clone your platform several time per second and never release those resources through destroy, then I think you will run into problems.

Okay. I tested one more time and using disable and your code keeps it only at 5 platforms and the frames consistently at 60!

I turned the populate script back on and the frames went really down. :frowning:

Why does every platform has all of this as children?

Because every time it fires the event, ALL of the spawners run the code to make an obstacle, which results in what you see.

Also, how do you get that? That would be very helpful.