NeuroGoblin
NeuroGoblin9mo ago

How to make a custom model using a type other than Color?

Hey guys! I have been following the Synchronising Custom Data guide (https://normcore.io/documentation/realtime/synchronizing-custom-data) and managed to get the ColorSync working successfully. I now want to change this to allow for strings to be sent to all clients, to update a TextMeshPro component. I replicated all the steps for the Color guide, but the delegate events such as textDidChange are not being generated from the model (see pic). This is my Model file: using System.Collections; using System.Collections.Generic; using UnityEngine; using Normal.Realtime; using Normal.Realtime.Serialization; [RealtimeModel] public partial class TextSyncModel { [RealtimeProperty(1, true, true)] private string _messageText; } For some reason, the code is not autogenerating like the ColorSyncModel did, and there is no option to manually re-generate. I am using Unity 2022.3.11. The only thing I did differently is I copy/pasted all the color scripts (colorsync, colorsynctest, colorsyncmodel) and changed the code to reflect a string instead of colors. The model has no compliation errors, and I tried deleting it and re-writing it from scratch. Any help would be greatly appreciated!
Synchronizing Custom Data | Normcore Documenation
In this guide, I’m going to walk you through how to synchronize custom data in your Unity application using custom realtime components.
No description
Solution:
the name of the didChange event is prefixed by the property name, in your case messageTextDidChange
Jump to solution
6 Replies
kapa.ai
kapa.ai9mo ago
Hi @NeuroGoblin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided, it seems like you're on the right track. Your TextSyncModel class looks correct, and it should work similarly to the ColorSyncModel class. However, there are a few things you might want to check: 1. Unity Version: According to the documentation (https://normcore.io/documentation/realtime/synchronizing-custom-data#generating-model-code-in-unity-2021), if you're using Unity 2021 or newer, Normcore will automatically generate the remaining code needed to use your model. The extra code exists as temporary C# code generated when your project compiles. You might not see it in your file, but it should be there when your project compiles. 2. Serialization: Only primitives (int, float, Vector3, string, etc.) can be serialized. 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. This is mentioned in the Common Questions (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) section of the documentation. 3. Compile Errors: Make sure your Unity project has no compile errors. If Unity is unable to compile this class, it will be unable to detect the changes you’ve made to your model. This is mentioned in the Generating model code in Unity 2019/2020 (https://normcore.io/documentation/realtime/synchronizing-custom-data#generating-model-code-in-unity-2019/2020) section of the documentation. If you've checked all of these and you're still having issues, it might be a good idea to reach out to the Normcore support team for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@196555254496493568> kapa.ai is still learning and improving, please let us know how it did by reacting below
Solution
Mechabit
Mechabit9mo ago
the name of the didChange event is prefixed by the property name, in your case messageTextDidChange
Mechabit
Mechabit9mo ago
if you use visual studios it will show up on the auto complete
NeuroGoblin
NeuroGoblinOP9mo ago
@Mechabit thank you so much! that worked
Mechabit
Mechabit9mo ago
np