MasterOX 水
MasterOX 水2mo ago

how to sync multiple values in a model

how do i have one model script that syncs multiple values
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To synchronize multiple values in a model in NormalVR, you can define multiple fields in your RealtimeModel class and annotate them with the [RealtimeProperty] attribute. Each field represents a different value that you want to synchronize. Here's an example of a RealtimeModel that synchronizes multiple values:
[RealtimeModel]
public partial class MyModel {
[RealtimeProperty(1, true )] private string _name;
[RealtimeProperty(2, true )] private Color _avatarPrimaryColor;
[RealtimeProperty(3, true )] private Color _avatarAlternateColor;
[RealtimeProperty(4, false)] private Vector3 _movementVelocity;
}
[RealtimeModel]
public partial class MyModel {
[RealtimeProperty(1, true )] private string _name;
[RealtimeProperty(2, true )] private Color _avatarPrimaryColor;
[RealtimeProperty(3, true )] private Color _avatarAlternateColor;
[RealtimeProperty(4, false)] private Vector3 _movementVelocity;
}
In this example, the model synchronizes a string (_name), two colors (_avatarPrimaryColor and _avatarAlternateColor), and a Vector3 (_movementVelocity). Each [RealtimeProperty] attribute takes three arguments: 1. A unique ID for the property (must be unique within the model). 2. A boolean indicating whether the property should be synchronized when it changes. 3. An optional boolean indicating whether a change event should be added to the model for this property. After defining your model, you need to compile it in Unity. Normcore will then generate the necessary code to keep the model in sync with the datastore. Remember, models are designed to synchronize data that can be easily serialized and transmitted to other clients. It is not possible to store a complex object, such as a Material or Texture, in a model. You'll need to pick out the pieces of data you would like to synchronize and use a RealtimeModel to synchronize them. For more information, you can refer to the RealtimeModel documentation (https://normcore.io/documentation/room/realtimemodel) and the guide on synchronizing custom data (https://normcore.io/documentation/realtime/synchronizing-custom-data). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below