vconquestV
Normal2y ago
7 replies
vconquest

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:

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.
Was this page helpful?