RepNotify with additional information

Hi there,

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

Hey Richard,

If you are in C++ you can add a parameter to your OnRep function and that will automatically be the old value. I hope I understood your question correctly :slight_smile: Please let me know if this didn’t work.

Thanks,
Osman

Hi Richard,

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.

Thanks for your quick reply and yes, you understand correctly.
We do have access to C++ but this class is fully in Blueprints and we’d rather not switch it to code if possible but we will if we have to. Is there another way of doing this in blueprints?

Thanks

  • Rich