Explain to me how the MVC structure should be organized for small syncs.
How can I get a cosmetic to sync between clients?
27 Replies
Hi @Alix Ollivier. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To explain how the MVC (Model-View-Controller) structure should be organized for small syncs in NormalVR and how to sync cosmetics between clients, let's break it down based on the information from the knowledge sources:
1. MVC Structure:
NormalVR uses an MVC-based architecture to establish a clear separation of concerns for networking code. According to the Client Architecture documentation:
- Model: The datastore holds a collection of RealtimeModel objects that are kept in sync between clients.
- View: In Unity, each GameObject represents the visual state of your app.
- Controller: RealtimeComponent scripts act as the controller.
2. Syncing Cosmetics:
To sync cosmetics between clients, you'll need to create a custom RealtimeComponent and RealtimeModel. Here's how you can do it:
a. Create a RealtimeModel:
First, create a model to hold the cosmetic data. For example:
b. Create a RealtimeComponent:
Next, create a RealtimeComponent to sync the cosmetic data between the model and the Unity scene:
c. Usage:
Attach the CosmeticSync component to the GameObject that represents your cosmetic item. When you want to change the color, call the SetColor method on the CosmeticSync component.
This structure follows the MVC pattern as described in the Synchronizing Custom Data guide:
- Model: CosmeticModel holds the synced data
- View: The GameObject with the Renderer component
- Controller: CosmeticSync component manages the synchronization
By using this structure, any changes made to the cosmetic (in this case, the color) on one client will automatically sync to all other clients connected to the same room.
Remember to add a RealtimeView component to the GameObject and ensure that the CosmeticSync component is listed in the observed components of the RealtimeView.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant Are these usually in separate scripts or the same script?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on the knowledge sources and the previous conversation, I can provide some clarification on how these components are typically organized in NormalVR:
The Model and the RealtimeComponent (which acts as the Controller) are usually created in separate scripts, but they work together closely. Here's a breakdown:
1. Model Script:
The RealtimeModel (in our previous example, the CosmeticModel) is typically defined in its own script. This follows the pattern shown in the Synchronizing Custom Data guide, where the model is defined in a separate file, for example,
CosmeticModel.cs
.
2. RealtimeComponent Script:
The RealtimeComponent (in our example, CosmeticSync) is also typically defined in its own script. This component acts as the Controller in the MVC pattern and is responsible for synchronizing data between the Model and the View (GameObject in the scene).
3. View:
The View in this context is not a separate script, but rather the GameObject in the Unity scene with its attached components (like Renderer).
So, to directly answer your question: The Model (CosmeticModel) and the RealtimeComponent (CosmeticSync) are usually in separate scripts, while the View is represented by the GameObject and its components in the Unity scene.
This separation of concerns allows for better organization and modularity in your code, making it easier to manage and maintain as your project grows.
Remember, when using these components, you'll need to ensure that:
1. The Model script is compiled correctly (for Unity 2019/2020, you need to manually compile the model as described in the model compilation guide).
2. The RealtimeComponent script is attached to the appropriate GameObject in your scene.
3. A RealtimeView component is also attached to the GameObject, with the custom RealtimeComponent listed in its observed components.
This structure allows NormalVR to efficiently synchronize your custom data across all connected clients.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant I just want the color of a trail renderer attached to the player avatar to be synced across clients. Do I really have to do all this work to rebuild my script into 2 separate scripts so I can sync it?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on the information provided in the knowledge sources, I understand your desire for a simpler solution to sync the color of a trail renderer across clients. However, the recommended approach in NormalVR does involve creating separate model and component scripts for proper synchronization.
That said, you don't necessarily need to rebuild your entire script. Instead, you can create a minimal model and component specifically for syncing the trail renderer color. Here's a streamlined approach:
1. Create a simple model script (e.g.,
TrailColorModel.cs
):
2. Create a minimal RealtimeComponent script (e.g., TrailColorSync.cs
):
3. Attach this TrailColorSync
component to your player avatar GameObject that has the TrailRenderer.
4. Make sure there's a RealtimeView component on the same GameObject, and add TrailColorSync to its list of observed components.
5. In your existing script, instead of directly setting the trail renderer color, you can now call GetComponent<TrailColorSync>().SetColor(newColor)
to update the color, which will automatically sync across clients.
While this approach still requires creating two new scripts, it's a minimal implementation that focuses solely on syncing the trail color. You can keep most of your existing logic in your current script and only use these new components for the color synchronization.
This method follows the recommended practices for NormalVR as described in the Synchronizing Custom Data guide, while minimizing the changes you need to make to your existing setup.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant , if I gave you my current, nonsynced script, would you be able to split it into the model + controller scripts appropriately?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Certainly! I'd be happy to help you split your current, non-synced script into the appropriate model and controller scripts for NormalVR. This process would involve analyzing your existing code and reorganizing it to fit the Model-View-Controller (MVC) pattern that NormalVR uses for synchronization.
To do this effectively, I would need to see your current script. If you provide your non-synced script, I can guide you through the process of:
1. Creating a RealtimeModel to hold the synchronized data (in this case, likely the trail renderer color).
2. Transforming your existing script into a RealtimeComponent that acts as the controller, managing the synchronization between the model and the Unity scene.
This approach aligns with the best practices outlined in the Synchronizing Custom Data guide and would ensure that your trail renderer color syncs properly across all clients.
If you'd like to proceed, please share your current script, and I'll be glad to help you split it into the appropriate model and controller scripts for NormalVR synchronization.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant Can you read this?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, I can read your question. However, I'm specifically tuned to answer questions about NormalVR. If you have any questions related to NormalVR, its features, or how to use it in Unity, I'd be happy to help you with those. Is there anything specific about NormalVR you'd like to know?
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant Can you split the file I gave you so it syncs the color across clients?
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize, but I don't see any file or script that you've shared with me in our conversation history. You mentioned earlier that you might provide your current, non-synced script, but it seems that you haven't actually shared it yet.
To help you split your script into the appropriate model and controller components for NormalVR synchronization, I would need to see your current script. Without the actual code, I can't provide specific guidance on how to reorganize it.
If you'd like to proceed with splitting your script for NormalVR synchronization, please share your current script in your next message. Once you do that, I'll be able to guide you through the process of creating a RealtimeModel and transforming your existing script into a RealtimeComponent that syncs the trail renderer color across clients.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant Please split this file so it syncs colors.
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize, but I don't see any file or script that you've shared in our conversation history or in your current question. Without the actual code to analyze, I can't provide specific guidance on how to split it for color synchronization in NormalVR.
To help you split your script for color synchronization across clients, I would need to see your current script. If you'd like to proceed, please share your existing script in your next message. Once you do that, I'll be able to guide you through the process of:
1. Creating a RealtimeModel to hold the synchronized color data.
2. Transforming your existing script into a RealtimeComponent that manages the synchronization between the model and the Unity scene.
This approach will align with the best practices for NormalVR as described in the Synchronizing Custom Data guide.
If you have any other questions about NormalVR or need clarification on the synchronization process, feel free to ask.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
For anyone reading this, that guide Kapai suggested actually shows literally how to color sync.
@Alix Ollivier could be worth getting on the EasySync alpha. It makes this a lot easier. Check out the announcements channel and ping Tom if you’d like to try it out
Sounds great! @Tom I'm interested.
hey Alix you also here haha
@Mikameel Yeah haha, turns out a ton of people in our group chat are all using normal. Golf + , Derby, Xulipa's game, etc. I'm loving it so far!
@kapa.ai Do you have any information on the EasySync Alpha?
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize, but after carefully reviewing the provided knowledge sources, I don't have any specific information about an "EasySync Alpha" feature for NormalVR. The knowledge sources don't contain any mentions of this particular feature or alpha version.
However, if you're looking for easier ways to synchronize data in NormalVR, I can provide some general information about their synchronization methods:
1. NormalVR uses a Model-View-Controller (MVC) architecture for synchronizing data across clients, as described in the Client Architecture documentation.
2. For synchronizing custom data, NormalVR provides a system using RealtimeModel and RealtimeComponent, which is explained in the Synchronizing Custom Data guide.
3. For simpler synchronization of transforms, NormalVR offers a built-in RealtimeTransform component, as detailed in the RealtimeTransform documentation.
If "EasySync Alpha" is a new feature or update that's not covered in the provided documentation, I recommend checking the official NormalVR website or contacting their support team for the most up-to-date information. Alternatively, you might find more recent information on their Discord channel.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.