[SOLVED] Check if Entity Visible Confusion

Hi, I want to see which balls are visible so I am trying something like:

if(balls[i].model.meshInstance.visible == true)
    //do stuff

But I just get the error: Cannot read properties of undefined (reading ‘meshInstance’)

Whats wrong here? Each ball entity has a render/asset component.


If the Entity has a render component and no model component, then getting the model component (entity.model) is going to return undefined because it doesn’t have a model component.

Because I just followed what someone else did. So I need to do:

So why are you trying to access the model component? :thinking:

You will need the entity, access the render component of the entity and then the mesh instances from the render component.

Related API docs

Hmm, forgive me, but I don’t really understand the help very well. I’ve tried each of the following, but I get errors each time:

balls[i].render.meshInstance.visible == false;
balls[i].render.meshInstance[0].visible == false;
balls[i].render.MeshInstances[0].visible == false;

You cannot test .visible member, this is valid only within rendering itself.
The way to do this is using visibleThisFrame - search existing forum post for this.

Okay Thanks. But when I try the following it returns true all the time… whether I’m looking at the mesh or not.


Any idea why?

Ah. Frustrum culling was not enabled on the camera. Thanks!! It works now!

Just to clarify on this post for anyone else that comes across this, neither meshInstance or MeshInstances exist on the the pc.RenderComponent class. The needed property is meshInstances which can be found on the API docs for the render component