☑ Cannot disable entity

hey guys,

can it be that the .enabled attribute from the pc.entity got lost during the port to the new scripting system?
Its still in the documentation, but I cannot access it anymore in the engine.
I logged a few entities to the console, but the public .enabled attribute isnt there anymore.

Is there a new way to enable or disable entities now, or is the attribute just missing in action?



Nope, it’s still there:


(pc.Entity inherits from pc.GraphNode)

Can you post a small reproducible illustrating the problem?

I made another test scene Martin, it does work hereI don’t know why it doesn’t work in our other project. edit: it just wasn’t triggered correct in our main project.

If you want add me to your problematic project and I can have a look - my username is vaios.

Thanks, but I think I figured it out for that project,
the function just wasn’t triggered correctly.
Martin might still have trouble with his project though.

Sounds like scope problem where this refers to something else, so you do: this.entity.enabled and actually this is not script, so it can’t refer to entity.
Please use Dev Tools with Breakpoints in Sources tab, that allows you to pause code and inspect variables.

Indeed, it seems to be something different, that causes the problem.

Although I cannot figure out what causes the problem yet.
I made a simple test script, which tries to disable all its children and tested that in two projects.
The same script works in a new created project, but not in my existing one.

Test script:

ToggleEntities.prototype.initialize = function() {
    console.log("This: ", this.entity );

ToggleEntities.prototype.hideObjects = function() 
    console.log("This2: ", this.entity );
    for(var o = 0; o < this.entity.children.length; o++)
         this.entity.children[o].enabled = false;   

The scope seems to be identical. I have also disabled all other scripts in the old project and tried the test project with a mesh from the old project. No clue what I am missing :disappointed_relieved:

Old Project: https://playcanvas.com/project/417420/overview/photogrammetry-example-viewer
New Project: https://playcanvas.com/editor/scene/454309

Any ideas?

Could you give a link to exact script file having a problem and tell me what line of code you have issue with?


This is the debug script:

and line 16 is causing the error:
this.entity.children[o].enabled = false;

This line is actually fine, what happens inside is a bit weird, it goes into internals and then tries to remove model from scene, and has to mark used materials as unused, but it fails to do so because one of meshInstances is not meshInstance, but empty array - weird.
Do you modify meshInstances of a model anywhere?

EDIT: try disabling “static” check on Log Top?

Yeah that’s the weird thing.
I disabled the static, but that’s not fixing the problem, but I think I found what’s causing the problem.

Thought I had disabled all other scripts in the scene, but I just noticed, that the turntable camera script is still active and that seems to cause the problem. If that’s disabled the rest works, now I just have to figure out what exactly is causing the error there :worried:

I am not manipulating any entities there, but I am looking up their positions and bounding box, to place the camera centered on the objects, I guess something in there is the root of the problem.
Soo time for more debugging :wink:

In turnable_camera.js, line 315 looks alarming to me :slight_smile:

Remember, that entity.model.meshInstances - is original array, and shall not be modified. If you need to clone the array, do:

var meshes = entity.model.meshInstances.slice(0);

Oh indeed,
thanks max, I think I would have looked for that a bit longer.
Slightly dump error :sweat_smile:

I might should take a bit more time to clean up my older scripts :stuck_out_tongue:

So as usual, thanks for the quick hlep guys, now I can continue to produce some more mess :sunglasses:

1 Like

You doing cool looking mess though! :wink:

these models are more meant as examples for my report.
However, if I find the time for it, I would like to do a small scene, with a bit more tweaked visuals and an propper environment around it.

I think that would be even cooler :grin:

1 Like