[SOLVED] How to reduce lag in my project?

The entity called “Flashlight Zones” is causing lots of lag (I am guessing because of all the boxes and stuff) is there a way to make the game run smoother? I was thinking if I can manually set the game fps to 30 it will be better because the computer wont be over pushing and decrease frame drops, I don’t know, I just need help. Thanks in advanced.

Hi @Brent_Reddick!

Below some tips.

  • Use compound collision if your entity has a couple of child entities with a collision component. (With compound collision on the parent entity, you only need a rigidbody component on the parent entity).
  • Be sparing with the use of lights in your scene, because this also costs a lot of performance.
  • Use low-resolution textures. (In many cases this does not need to be higher than 512x512).

So funny enough, I already got most of that, the area that is laggy uses compound collision, and the game has no textures at all, but how can I reduce lag with the lights without changed much? Thx for the tips btw.

It can be a specific thing that can cause lag. I suggest to temporarily disable some components of your scene to find out if something cause the lag. (You can also use some browser tools to find out, but you need to understand how they work and I can’t help you with that).

Disabling shadows can save a lot. You probably don’t need shadows from all the lights.

I have the shadows set to only render once, do they still cause lots of lag that way?

No, only real time shadows I guess.

I think its my device, can you tell me if you get any lag?

https://playcanvas.com/editor/scene/1903823

btw ignore the enemy he cant kill you yet

Can you tell me at what point in the game you experience the lag?

I’m sure my enemies can. They are very smart. They just try to fool you. :upside_down_face:

lol, my game is always laggy for me when I have the flashlight zones enabled, but I think its the device

Also I want the game to be forced to run at 30 fps so it can work smoothly on less powerful devices and reduce lag

I see with the mini stats you have a lot of draw calls. Sometimes 640, while in my TopDown project I have less than 50 draw calls. Since you have many of the same entities in your project, I think you can easily batch those entities. I don’t know exactly how it works, but I think if you create a batch group for a specific entity and you have 50 of them, you only have 1 draw call instead of 50.

https://developer.playcanvas.com/en/user-manual/optimization/batching/

You can enable the mini stats on the launch settings.

image

I also suggest to use templates.

With a template you can change an entity and apply this change to all other entities that are the same template as well.

https://developer.playcanvas.com/en/user-manual/templates/

So if I put everything in 1 batch group that would reduce lag by a lot, or is everything crammed in one batch group a bad thing? Thanks for telling me this by the way there was no way I could have discovered this without you :slight_smile:

You can can add the same entities to a batch group. Please read the page I shared what are the requirements. I think in your case you can create a couple of groups for example for the chairs, tables and lamps.

In my own project I have four batch groups at the moment.

You can create a new group in the project settings.

If you have created a group you need to assign every entity to the group as well.

image

Thanks! I also read on Batching | Learn PlayCanvas that all entities “primary rule is that all mesh instances must share the same material.” which I think is the same thing and it makes sense to.

also wdym by you need to assign every entity to the group as well.

If I look again at your project, in your case it is a little more difficult, because for example your chair consists of a couple of different entities. I think your chair could have a batch group for the seat and back and a batch group for the legs. Without templates you will have to assign manually all entities to the correct batch group.

image

I suggest to try out using templates and batch groups in an empty project and if you have success with it, you can rebuild your scene with the templates you have created.

so a template would merge all the entities into one chair entity?

In the example of the chair, the parent entity with the name ‘Chair’ will be the template entity. If you make a change to this entity (or the children), you can apply this change to all other templates as well (so the other ‘Chair’ entities that are the same template).