LuckBringer
LuckBringer5d ago

Is it possible to network synced variables such as Lists or Dictionaries with Normcore?

I was wondering if it was possible to sync Lists or Dictionaries as a DataModel?
2 Replies
kapa.ai
kapa.ai5d ago
Hi @LuckBringer. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to synchronize collections like Lists and Dictionaries with Normcore, but not directly using built-in C# collections. Instead, Normcore provides its own specialized collection types that are designed for efficient networking and synchronization. According to the Collections documentation (https://normcore.io/documentation/room/collections), Normcore offers the following collection types: 1. RealtimeSet 2. RealtimeDictionary 3. RealtimeArray 4. StringKeyDictionary These collections are designed to be atomic and handle simultaneous changes from multiple clients without conflicts. They also provide efficient synchronization, only sending the minimal amount of information needed for updates. It's important to note that standard C# collections like List<> and Dictionary<> are not supported directly. As stated in the documentation: Built-in C# collections like List and Dictionary are not supported because Normcore cannot efficiently detect when their contents have changed. (https://normcore.io/documentation/room/collections) Instead, you should use Normcore's provided collections in your RealtimeModels. For example, you can use RealtimeArray as an alternative to List, and RealtimeDictionary or StringKeyDictionary as alternatives to Dictionary. Here's an example of how you might use a RealtimeArray in a model:
[RealtimeModel]
public partial class MyModel {
[RealtimeProperty(1, true)]
private RealtimeArray<RibbonPointModel> _ribbonPoints;
}
[RealtimeModel]
public partial class MyModel {
[RealtimeProperty(1, true)]
private RealtimeArray<RibbonPointModel> _ribbonPoints;
}
This example is taken from the Creating a Multiplayer Drawing App guide (https://normcore.io/documentation/guides/creating-a-multiplayer-drawing-app#making-it-multiplayer). By using these Normcore-specific collections, you can efficiently synchronize complex data structures across your networked application. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5d ago
<@178941228967133195> Kapa.ai is still learning and improving, please let me know how I did by reacting below.