vconquest
vconquest2mo ago

Toggle UI visibility on button clicked

I'm new to Normcore and working on an application moving objects and creating UI callouts for those objects when buttons are pressed. I have the synchronization for the objects working properly calling but am having difficulty showing visibility of the UI information. The UI is a child of each object so as it moves when the button is pressed or rotates with the slider the UI follows along with it. What is the best approach to toggle and sync this UI visibility?
Solution:
---------------------- To synchronize the visibility of a UI element in Normcore, you can create a custom RealtimeComponent. This component will synchronize the state of the UI visibility between the Unity scene and the Normcore datastore. Here's a general approach: ...
Jump to solution
6 Replies
kapa.ai
kapa.ai2mo ago
Hi @vconquest. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Solution
kapa.ai
kapa.ai2mo ago
---------------------- To synchronize the visibility of a UI element in Normcore, you can create a custom RealtimeComponent. This component will synchronize the state of the UI visibility between the Unity scene and the Normcore datastore. Here's a general approach: 1. Create a new script for the component and a model to put in the datastore. For example, you can name these UIVisibilitySync.cs and UIVisibilitySyncModel.cs respectively. 2. In the UIVisibilitySyncModel.cs, define a property for the visibility state of the UI. 3. In the UIVisibilitySync.cs, override the DidConnect and DidDisconnect methods to update the visibility of the UI based on the model's state. 4. Add the UIVisibilitySync component to the UI game object in Unity. 5. When a button is pressed, update the visibility state in the UIVisibilitySyncModel and Normcore will automatically synchronize this state across all clients. Please note that Normcore does not synchronize parent-child relationships between objects. If the UI is a child of another game object and the parent gets destroyed, it will take the RealtimeView and its components with it, which can result in desyncs between your clients. Therefore, it's generally recommended not to reparent a game object with a RealtimeView or RealtimeComponent on it.
kapa.ai
kapa.ai2mo ago
For more detailed instructions on creating a custom RealtimeComponent, you can refer to the Synchronizing Custom Data (https://normcore.io/documentation/realtime/synchronizing-custom-data) guide in the Normcore documentation. For more information on the potential issues with reparenting game objects, you can check out the Common Questions (https://normcore.io/documentation/realtime/common-questions#can-i-reparent-a-game-object-with-a-realtimeview-or-realtimecomponent-on-it) section. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@682254482700107802> kapa.ai is still learning and improving, please let us know how it did by reacting below
fojam
fojam2mo ago
I would say the above explanation pretty much got it. Just make a bool property on your realtime model and listen for the didChange event on it, and just toggle SetActive on your UI gameObject whenever it changes
vconquest
vconquest2mo ago
Thanks, will give it a try.