What are the tradeoffs between using AssetContainers and Node.SetEnabled() to “add/remove” items from a scene?
Here is a simple PG showing the two options:
My understanding is that AssetContainer is an abstract scene itself, and so acts as a temporary holder of assets that are moved in to it. Putting an item in the container completely removes it from the current scene.
I haven’t yet researched exactly what setEnabled does, but I assume it removes the node from the rendering pipeline, even though it remains in the scene.
At first glance, AssetContainer might seem the more efficient when needing to move nodes in/out of scenes. It also supports items other than Nodes. However, for nodes specifically, could AssetContainer have been implemented with SetEnabled instead? What would be the tradeoffs?
I think my question is useful regardless of my motivation for asking it, but in case it matters…
The reason for asking is that I believe the currently recommended approach for switching between multiple “scenes” in WebXR is to use an AssetContainer for moving items in/out of the scene as needed. (The other option is to render multiple scenes in a single render loop, but I think that’s inefficient and might have other problems.)
However, I’m finding that having to manage assets using AssetContainers to be complex with WebXR. (Consider that once WebXR is initialized, we can’t simply use methods like moveAllFromScene
. See this issue for details.)
Some of the complexities are evident in this previous thread by @MarkM. For example, I’m parenting GUI items to controllers that can come and go. i.e. If I switch “scene”, I also need to cleanup the GUI elements attached to the controllers, etc. This is all doable with AssetContainers …it just gets complex. So before I invest too much more in to this approach, I wanted to first make sure AssetContainers are still the best option. If I were to implement a more custom approach, setEnabled seems very relevant.