Description
I have a managed collection in a NetworkVariable, e.g. NetworkVariable<List<Condition>> _conditions.
I sometimes change this collection and call _conditions.CheckDirtyState(true) - this should check if the variable changed and invoke the OnValueChanged(...) event if it actually changed.
However the following code doesn't seem to work correctly for the owner/server:
NetworkVariable<List<Condition>> _conditions; // This condition currently has one element
// ...
var firstCondition = _conditions.Value[0];
_conditions.RemoveAt(0);
_conditions.CheckDirtyState(true); // This triggers the event, with oldList.Count = 1, newList.count = 0
_conditions.Insert(0, firstCondition); // The list is now equal to the original list
_conditions.CheckDirtyState(true); // This won't trigger the event, because CheckDirtyState compares with the `m_PreviousValue` which hasn't been updated yet
// If I track the changes only by listening on the OnValueChanged event, I would still think that the list has 0 elements because that's the last invoked element
I obviously don't have the exact same code as written above, it just sometimes happens that the same condition is removed and then applied again from a different source.
Workaround
I can just invoke the events manually on the writer's side, so it's no big deal, but if it's easy to fix then it would probably help the next person that encounters this behavior and has to spend time debugging.
Description
I have a managed collection in a NetworkVariable, e.g.
NetworkVariable<List<Condition>> _conditions.I sometimes change this collection and call
_conditions.CheckDirtyState(true)- this should check if the variable changed and invoke theOnValueChanged(...)event if it actually changed.However the following code doesn't seem to work correctly for the owner/server:
I obviously don't have the exact same code as written above, it just sometimes happens that the same condition is removed and then applied again from a different source.
Workaround
I can just invoke the events manually on the writer's side, so it's no big deal, but if it's easy to fix then it would probably help the next person that encounters this behavior and has to spend time debugging.