My project has a bunch of labels which need to follow 3D points. That’s all working fine, but I’m stuck on the following:
The labels are in different areas - I need to be able to show/hide groups of them at a time from within my code. I thought the best option would be to put the TextBlocks into a GUI Rectangle per group which I could then show / hide - however I seemingly then can’t link the TextBlocks to meshes (TransformNodes), getting the error Cannot link a control to a mesh if the control is not at root level. I also just in case tried grouping the TransformNodes and setting their visibility, but as expected that doesn’t seem to affect the GUI TextBlock elements.
Is there a way to do this or do I just need a function that loops through all the AdvancedDynamicTexture elements, using names to work out which is in which group and setting visibility accordingly? I feel like there must be a way to group them or something - but maybe not?
An alternavive to keeping names and looping through elements for each name might be to keep an array or Map (one element per group) of WeakMap of uid to mesh structures. A WeakMap will keep elements only when referenced elsewhere (e.g. scene). Removing from scene should remove them from the WeakMap automatically.
A quick loop through a group wouldn’t require potentially-expensive lookups.
Yeah, this is a known limitation of GUI elements’ linkToMesh function. The elements must be at the root level (or the root itself), otherwise positioning won’t work as expected.
I am trying to think of a proper solution for that, but it really depends on the use-case and how many elements you want to render. I very much like the idea of storing groups in your own application and iterating through these structures (array/set/map?) to turn on/off a specific group. This is the simplest and most straight-forward solution I can think of.
Thanks for your input I’ve ended up going with the option of storing groups and iterating through them in my own code, and it does indeed work without any issues.
It simply surprised me that there was no way to create hierarchy in the GUI if I want the children to be linked to meshes. It does kind of make sense though I guess, as it would be “breaking the hierarchy” as the children wouldn’t be following the parent…
yep, this is the reasoning behind it. I do agree that we could have created some form of a “group” control that will contain more than one control and has no influence on their position. But that would make the entire API a bit more complicated