Synchronized Dictionary, or most commonly referred as "SyncDictionary" are easily definable in your code, and will handle automatically align a dictionary between all players.
In theory, you could just convert a dictionary to a SyncDictionary, and it should work. Working with it is the exact same with adding, setting, removing or clearing.
SyncDictionaries are built with the Network Module setup, meaning that you have to initialize it. Below is a usage example:
//Creates a new instance of the dictionary - `true` means it is owner auth. [SerializeField] privateSyncDictionary<int,float> myDictionary =new(true);protectedoverridevoidOnSpawned(){ //Subscribing to changes made to the dictionarymyDictionary.onChanged+= OnDictionaryChanged;}privatevoidOnDictionaryChanged(SyncDictionaryChange<int,float> change){ //This is called for everyone when the dictionary changes. //It will log out the Key, Value and operationDebug.Log($"Dictionary updated: {change}");}privatevoidChangeMyDictionary(){ //This will change or add a value to the dictionarymyDictionary[123] =0.69f; //This will remove the value from the dictionarymyDictionary.Remove(123); //This will clear the dictionarymyDictionary.Clear(); //This will mark the key as dirtymyDictionary.SetDirty(123);}
The SyncDictionary is custom serialized in editor, in order to make visual debugging easier.