[Closed] RepNotify with additional information
This question is really asking for advice about how best structurally to tackle a problem we are having with RepNotify.
We have lots of Characters in the world. Each character has a CharacterSheet, which contains most importantly an integer array of stats, e.g. Agility, Strength, Armour, Health. The stat array is indexed by a StatType enum.
The Character Sheet has a function on it called SetStat(StatType stat, int32 newValue). We currently have the Stat int array set to RepNotify and the OnRep_Stats function calls an EventDispatcher called OnStatChanged which notifies the UI binds to so that it can update when a stat has changed.
This was working fine, however now we need more information. When the stat changes, I need the OnStatChanged Event to know what stat has changed, what the old value was and what the new value is. i.e. OnStatChanged( StatType Stat, int32 OldValue, int32 New Value). However, RepNotify only tells clients when a stat has changed, and doesn't know have this information.
Is there a nice way to do this? We have ideas, but none of them seem great. Any advice would be much appreciated.
Thanks, - Rich
The question has been closed Mar 27 '16 at 02:43 PM by AndrewHurley for the following reason:
The question is answered, right answer was accepted
We would like to support RepNotify parameters in blueprints at some point, but for now you'll have to use a workaround. In addition, there is currently a known issue with C++ RepNotify array parameters, which we also hope to fix.
The easiest workaround that comes to mind is to store your own "shadow" copy of the replicated array on the object. When the client receives the OnRep, it can compare the shadow copy to the current array to determine what changed and act on it, if necessary. Afterwards, it would store the current array into the shadow array. This is essentially what the engine does behind the scenes in order to know when to call RepNotifies.
answered Mar 27 '16 at 02:42 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here