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?
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:
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.