35 Replies
Hi @CanyonsEcho. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To sync a TMP_Text (TextMesh Pro object) in NormalVR, you cannot directly sync the object as only primitives (
int
, float
, Vector3
, string
, etc.) can be serialized. Instead, you should create a field for each property on the object that you’d like to sync.
For example, if you want to sync the text content and color of a TMP_Text object, you would create separate fields for these properties and sync them individually.
Here is the relevant information from the knowledge source (https://normcore.io/documentation/room/common-questions#when-i-try-to-sync-a-specific-object-to-the-datastore-i-get-an-error-that-says-it-cannot-be-serialized-whats-the-issue):
Only primitives (---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------int
,float
,Vector3
,string
, etc.) can be serialized, so if you need to sync a specific kind of object like a TextMesh Pro object, you should create a field for each property on the object that you’d like to sync.
<@1170785024254169139> kapa.ai is still learning and improving, please let us know how it did by reacting below
how can i do that
@Normcore Assistant how can i do that
Let me check the knowledge base for you. One moment! :books:
----------------------
To sync a TMP_Text object in NormalVR, you would need to create a custom RealtimeComponent that synchronizes the properties of the TMP_Text object that you want to sync. Here's a general outline of the steps you would need to follow:
1. Create a RealtimeModel subclass: This model will hold the data you want to sync. In this case, it could be the text content and color of the TMP_Text object. You would create a new script, say
TMP_TextSyncModel.cs
, and define the properties you want to sync in this model.
2. Create a RealtimeComponent subclass: This component will be responsible for syncing the state between the Unity scene and the model in the Normcore datastore. You would create another script, say TMP_TextSync.cs
, and in this script, you would implement the logic to update the model when the TMP_Text object changes and vice versa.
Here's a simplified example of what the TMP_TextSync.cs
script might look like:
In this example, TMP_TextSyncModel
would be a model that has properties for the text content and color of the TMP_Text object.
Please note that this is a simplified example and you would need to add more code to handle registering and unregistering from events, as well as to handle syncing the state when the model changes.
For more detailed information on how to create custom RealtimeComponents and RealtimeModels, you can refer to the Normcore documentation (https://normcore.io/documentation/realtime/synchronizing-custom-data).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1170785024254169139> kapa.ai is still learning and improving, please let us know how it did by reacting below
i only need to sync text
@Normcore Assistant i only need to sync text
Let me check the knowledge base for you. One moment! :books:
----------------------
If you only need to sync the text content of a TMP_Text object, you can simplify the process. Here's how you can do it:
1. Create a RealtimeModel subclass: This model will hold the text content you want to sync. You would create a new script, say
TMP_TextSyncModel.cs
, and define the text property in this model.
2. Create a RealtimeComponent subclass: This component will be responsible for syncing the state between the Unity scene and the model in the Normcore datastore. You would create another script, say TMP_TextSync.cs
, and in this script, you would implement the logic to update the model when the TMP_Text object changes and vice versa.
In this example, TMP_TextSyncModel
is a model that has a property for the text content of the TMP_Text object.
Please note that this is a simplified example and you would need to add more code to handle registering and unregistering from events, as well as to handle syncing the state when the model changes.
For more detailed information on how to create custom RealtimeComponents and RealtimeModels, you can refer to the Normcore documentation (https://normcore.io/documentation/realtime/synchronizing-custom-data).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1170785024254169139> kapa.ai is still learning and improving, please let us know how it did by reacting below
where do i attach these scripts? @Normcore Assistant
Let me check the knowledge base for you. One moment! :books:
----------------------
The
TMP_TextSync.cs
script should be attached to the GameObject that has the TMP_Text component you want to sync. This is because the script uses GetComponent<TMP_Text>()
to get a reference to the TMP_Text component in its Awake()
method.
The TMP_TextSyncModel.cs
script doesn't need to be attached to a GameObject. It's a model class that's used by Normcore to sync data, so you just need to create the script and Normcore will use it automatically when you use the TMP_TextSync
component.
Here are the steps:
1. Create a new script in your Unity project, name it TMP_TextSyncModel.cs
, and paste the code for the TMP_TextSyncModel
class into it.
2. Create another new script, name it TMP_TextSync.cs
, and paste the code for the TMP_TextSync
class into it.
3. In the Unity editor, select the GameObject that has the TMP_Text component you want to sync.
4. In the Inspector, click on the "Add Component" button.
5. In the search box that appears, type TMP_TextSync
and select it to add it to the GameObject.
Now, whenever you want to sync the text content of the TMP_Text component, you can call the UpdateModel()
method on the TMP_TextSync
component.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1170785024254169139> kapa.ai is still learning and improving, please let us know how it did by reacting below
@Normcore Assistant can i sync a standard cube or something using realtimeview and realtimetransform if its disabled and i use a script to enable it?
Let me check the knowledge base for you. One moment! :books:
----------------------
No, you cannot sync a standard cube or any other GameObject using RealtimeView if it's disabled. As per the Normcore documentation (https://normcore.io/documentation/realtime/common-questions#can-i-disable-realtimeview), Scene RealtimeViews register with Realtime in
Start()
. If they are disabled, they will never register: Realtime will neither initialize them nor connect them to the datastore.
Instead, you can use a custom RealtimeComponent to enable/disable child game objects, scripts, or renderers directly.
For synchronizing a GameObject like a standard cube, you can use the RealtimeTransform component. Here's how you can do it:
1. Create an empty scene. Add a Realtime component to an empty game object and configure the appKey so it can connect.
2. Create a Cube game object in the scene and add a RealtimeTransform component to it.
3. Export a build, and open it next to the editor. Hit Play in Unity.
4. Click the "Request Ownership" button on the RealtimeTransform inspector (not the RealtimeView inspector).
5. Drag the cube around in the scene and watch how it updates on the build automatically.
You can find more details in the Normcore documentation (https://normcore.io/documentation/realtime#synchronizing-a-gameobject).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1170785024254169139> kapa.ai is still learning and improving, please let us know how it did by reacting below
how can i do that @Normcore Assistant