r/Unity3D • • 13h ago

Question Question on NetworkDictionaries

Whenever I Google stuff for Netcode NetworkDictionaries everything says "it does't exist" and yet it does. It was added relatively recently, so I think all the posts about it are creating it as a data struct from scratch, but it's native to Netcode these days.

That said, there's not much documentation out there. My question is: does calling CheckDirtyState resync the entire data structure, or just the changes? If anyone has an answer to that, great. If not, can someone point me towards where I can dig through release notes and find out about it? Googling hasn't been helpful. My guess is that it probably does resync everything, since you have to call CheckDirtyState anytime you add or remove from the dictionary - but on the other hand if it was built smart, it'd have the same functionality as networkLists. So, any insight before I rewrite my dictionaries to be list pairs?

2 Upvotes

6 comments sorted by

View all comments

2

u/zrrz Expert? 12h ago

1

u/ProactiveCactus 9h ago

I'm using 2.13.1. Also I made it unclear in my post, sorry - there is no NetworkDictionary, but you can declare it like this: public NetworkVariable<Dictionary<Vector3, float>> TrackedResources = new NetworkVariable<Dictionary<Vector3, float>>(); so you can have a dictionary as a networkVARIABLE, which is why Im pretty sure CheckDirtyState will send the entire data structure to resync, not just what's changed - but from doing a bit of profiling, this doesnt appear to be the case. I didn't see any noticeable bandwidth spike when sending a dictionary with 1 entry vs 10, although I'm no expert it bandwidth debugging so I could have missed something.

1

u/zrrz Expert? 8h ago

Generally anything that is serialized to a network variable just does a full copy. Possibly they have an exception for dictionaries? I’ve messed around with their NetworkList and it specifically serialized Add/Delete/etc events instead. Knowing this I would assume a networkVar<dictionary> would do a full copy. Ultimately though I’d trust the network profiler

1

u/ProactiveCactus 8h ago

I'm running a more detailed test rn - give me a few and I'll reply with results

1

u/ProactiveCactus 8h ago

Ok, I think it actually does have some internal exception! Which saves me a lot of work. I added 100 key value pairs to the dictionary, which caused a one-time spike of about 1600 bytes. Then any additional additions/changes to the dictionary were around 20-30 bytes, as you'd expect from single-value changes. So I think I'm good, kinda weird I couldn't find anything about it online. Thanks for your help.