fgamez1020
fgamez10202w ago

Real time modelq

How Do I create a realtime model with 3 different values and how Do I handle those values
2 Replies
kapa.ai
kapa.ai2w ago
Hi @fgamez1020. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To create a RealtimeModel with three different values and handle them in NormalVR, you can follow these steps: 1. Create a RealtimeModel:
using UnityEngine;
using Normal.Realtime;

[RealtimeModel]
public partial class MyCustomModel {
[RealtimeProperty(1, true)]
private int _intValue;

[RealtimeProperty(2, true)]
private float _floatValue;

[RealtimeProperty(3, true)]
private string _stringValue;
}
using UnityEngine;
using Normal.Realtime;

[RealtimeModel]
public partial class MyCustomModel {
[RealtimeProperty(1, true)]
private int _intValue;

[RealtimeProperty(2, true)]
private float _floatValue;

[RealtimeProperty(3, true)]
private string _stringValue;
}
This example creates a RealtimeModel with three different value types: int, float, and string. 2. Compile the model: After creating your model, you need to compile it. In Unity 2021+, this happens automatically. For older Unity versions, you need to manually compile the model using the "Compile Model" button in the inspector. 3. Handle the values: To handle these values, you can create a RealtimeComponent that uses this model:
using UnityEngine;
using Normal.Realtime;

public class MyCustomComponent : RealtimeComponent<MyCustomModel> {
private void Update() {
// Set values
model.intValue = 42;
model.floatValue = 3.14f;
model.stringValue = "Hello, Normcore!";

// Get values
Debug.Log($"Int: {model.intValue}, Float: {model.floatValue}, String: {model.stringValue}");
}
}
using UnityEngine;
using Normal.Realtime;

public class MyCustomComponent : RealtimeComponent<MyCustomModel> {
private void Update() {
// Set values
model.intValue = 42;
model.floatValue = 3.14f;
model.stringValue = "Hello, Normcore!";

// Get values
Debug.Log($"Int: {model.intValue}, Float: {model.floatValue}, String: {model.stringValue}");
}
}
This component allows you to set and get the values from your model. The changes will be automatically synchronized across all clients connected to the same Normcore room. For more detailed information on creating and using RealtimeModels, you can refer to the following resources: Synchronizing custom data RealtimeModel Remember that RealtimeModels should be partial classes and shouldn't inherit from any other class. Also, make sure to use the supported primitive types for your properties as outlined in the Supported Primitives documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@1053407831916822528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?