Lights get disabled but the profiler show them

Hello i have this code

this.hour='day';
                this.cubemap.loadFaces = true;
                this.app.scene.skybox=this.cubemap.resource;
                this.app.scene.skyboxIntensity=1;
                this.app.scene.fogColor=new pc.Color(0.3,0.4,0.5);
                this.app.scene.skyboxMip = 1;
                this.light.light.color= new pc.Color(0.7,0.7,0.7);
                var lamp=this.app.root.findByTag('light');
                var lamp1=this.app.root.findByTag('lamp');
                for (var i=0; i<lamp.length;i++) {
                    lamp[i].light.enabled=false;
                    lamp1[i].model.model.meshInstances[7].material = this.texLamp[0].resource;
                }
                this.app.lightmapper.bake(null, pc.BAKE_COLORDIR);

but when i check the profiler it still show 12 lights, i have made a small test project but there it works fine…is there something wrong in my code?

Hi @ayrin,

I would check with the browser debugger how the code steps, if the loop works and disables the light components.

And also make sure there isn’t any other script/code that may be enabling the lights back on.

No @Leonidas the lights are just handled in the daynight cycle inside game.js

I just ran the game and these are the lights that are enabled:

10:03:46.004 pc-devtools.js:66     DirectionalLight [Top/DirectionalLight]
10:03:46.004 pc-devtools.js:66         Directional Light [Top/Barracks/Lamp/Directional Light]
10:03:46.006 pc-devtools.js:66         Directional Light [Top/Barracks/Lamp/Directional Light]
10:03:46.013 pc-devtools.js:66         Directional Light [Top/Tower/Lamp/Directional Light]
10:03:46.018 pc-devtools.js:66         Directional Light [Top/Apotecary/Lamp/Directional Light]
10:03:46.022 pc-devtools.js:66         Directional Light [Top/Inn/Lamp/Directional Light]
10:03:46.024 pc-devtools.js:66         Directional Light [Top/Chapel/Lamp/Directional Light]
10:03:46.026 pc-devtools.js:66         Directional Light [Top/Chapel/Lamp/Directional Light]
10:03:46.028 pc-devtools.js:66         Directional Light [Top/ranger-tr/Lamp/Directional Light]
10:03:46.033 pc-devtools.js:66         Directional Light [Top/Shop/Lamp/Directional Light]
10:03:46.038 pc-devtools.js:66         Directional Light [Top/Blacksmith/Lamp/Directional Light]
10:03:46.044 pc-devtools.js:66         Directional Light [Top/Thieves/Lamp/Directional Light]
1 Like

Yes @yaustar i guessed it was those, but i don’t get why since no lights are shown and the code should disable them.
EDIT: checked with some breakpoints, the code is executed correctly, the lights turn off but it still says 12 lights.

That output of the lights is from going through all the entities in the game when it is running, checking if it’s a light and whether the entity is enabled or not.

When you turn off the lights, do you disable the Entity or the light component or a parent Entity?

Edit: Something is either creating them again or enabling them as they are enabled when the game is running.

When i turn off the lights i disable the light component the parent entity has just a change of texture, here is the full daynight cycle code (it’s called every 30 mins)

Game.prototype.daynight= function() {
            this.timestart=Date.now();
            if (this.hour==='day') {
                this.hour='night';
                this.cubenight.loadFaces = true;
                this.app.scene.skybox=this.cubenight.resource;
                this.app.scene.skyboxIntensity=0.1;
                this.app.scene.fogColor=new pc.Color(0,0,0);
                this.app.scene.fog='linear';
                this.app.scene.skyboxMip = 1;
                this.light.light.color= new pc.Color(0,0.1,0.3);
                var lamp=this.app.root.findByTag('light');
                var lamp1=this.app.root.findByTag('lamp');
                for (var i=0; i<lamp.length;i++) {
                    lamp[i].light.enabled=true;
                    lamp1[i].model.model.meshInstances[7].material = this.texLamp[1].resource;
                }
                this.app.lightmapper.bake(null, pc.BAKE_COLORDIR);
            } else {
                this.hour='day';
                this.cubemap.loadFaces = true;
                this.app.scene.skybox=this.cubemap.resource;
                this.app.scene.skyboxIntensity=1;
                this.app.scene.fogColor=new pc.Color(0.3,0.4,0.5);
                this.app.scene.skyboxMip = 1;
                this.light.light.color= new pc.Color(0.7,0.7,0.7);
                var lamp=this.app.root.findByTag('light');
                var lamp1=this.app.root.findByTag('lamp');
                for (var i=0; i<lamp.length;i++) {
                    lamp[i].light.enabled=false;
                    lamp1[i].model.model.meshInstances[7].material = this.texLamp[0].resource;
                }
                this.app.lightmapper.bake(null, pc.BAKE_COLORDIR);
            }
        };

Without playing till it’s dark, I can’t test if the lights are turned off during the dark.

It’s also worth noting that even then, 12 lights during the day cycle is a lot.

I would generally recommend having as few as possible and turning one on if the player is nearby.

Ehm no during day cycle just 1…at night they became 12 (11 without shadows), can’t turn on just one coz when play in first person you will see the far lights.
EDIT: i reduce the cycle day/night to 30 seconds

Anyway seems it’s just a bug of the profiler, all lights works fine and the game is not affected…also if something is slowing down the frame rate, is it possible to use an old version of ammo?

Yeah, it does look like a bug. Looks like it doesn’t update correctly :confused:

I will raise an issue on GitHub tomorrow about it

You can do (find an older release from the Ammo.js GitHub and replace the project files) but chances are that it will be slower than the WASM module that is currently there.

A quick profiler shows that ~90% of your frame is spent in physics so if it’s the terrain that’s causing the issue (branch the code and find a fast way to test), you really need to find a way to restructure the code to effectively get around it.

Is it all one large terrain? Have you tried to divide that up into much smaller pieces so you only have a few pieces loaded at once over all 900k polys?

A lot of your rigidbodies are kinematic, do they need to be? Can they be static instead? That can help a fair bit.

They can be static indeed, if it doesn’t affect the re-location when changing scenes, triangles are now 200k but still 10fps instead 35fps of old scripts, so i thought ammo version is the issue.

Hi @ayrin,

Have you tried gradually disabling your scene entities to identify what and how affects the frame rate?

If the scenes are exactly the same with exactly the same settings, it could be worth trying an older version of the engine to see if there has been change in how Ammo is used.

Ammo hasn’t changed that much but there has been some refactors around the physics code.

Do you have a link to the old version of the project?

https://playcanvas.com/project/352037/overview/kallen-supremacy

Yes @Leonidas i tried but foind nothing relevant.

In dungeon 60 fps

I did a quick test on the profiler for lights being turned off / on in a project and it looks like it is working correctly.