How to have an enabled entity not rendering

I have a few sections in my game, each one of which is contained in a separate entity and has its own handling script.

In other engines, the option to render an entity (“enabled”) is separate from the option to render it (“renderable” or “visible”), but it seems that both are tied in PlayCanvas, so the entities that are not displayed when my game opens (enabled = false) are not running their scripts, and therefore not making the required calls to the backend to populate their content.

I would like these entities to stay out of the render pipeline, but at the same time to be running their logic so when the time comes to show them they have already populated their content. What would be the best practice to achieve this result in PlayCanvas?

Thanks :slight_smile:

There is hide/show on the modelComponent:

Is that what you are looking for?

I need to use this in the UI, so these entities do not have a model component.

They are all Element Groups added to the UI, each one of them containing a whole hierarchy of UI elements inside.

My best guess now is to have them all “enabled” at the beginning, then let the manager that handles their visibility disable those not visible on the postInitialize method.

Hm. I see :thinking:

Haven’t got a good answer for that one beyond having the elements as a child of the logic entity as the way you have described.

If you would like this to be in the engine, you can request it as a feature here: https://github.com/playcanvas/engine/issues

1 Like

OK, thanks!

If your logic doesn’t require any element component related metric or input taken, then you can also disable at the component level. The entity will stay enabled (so scripts will run) but the element won’t render:

this.entity.element.enabled = false;

For model components it will be similar:

this.entity.model.enabled = false;
1 Like

Yeah, I’m afraid that doesn’t work for Element Groups in the UI, I already tried it :frowning:

Right, I think you will have to iterate on all child elements and do the same.

Disabling a component isn’t a change that automatically propagates to children.

1 Like

In my game I have a parent entity, which is always enabled and holds all my game views. It is responsible for switching those views and updating them before showing to the screen. The views themselves and their child elements may or may not contain scripts, but those do not depend on background services. For example a view could have a button, which has own script for firing an event that it was clicked. The script will work, because you can’t click a button without enabling its view first.

So, the parent UI holds all my views and manages them, but do not represent a view itself. Its children are the views that are actually shown to the screen.

From the screenshot you may see that UI entity holds all my views, and the scripts that manage each of the view. You can see that all the views are disabled, except Home, which the player sees the first when starts the game, and Widgets - those are real time short-lived self-hiding notifications, and appear on top of any screen, so its always enabled too.

2 Likes