TArray replication, RepNotify bug

Very strange behaviour of RepNotify and TArray.

I have this array:

UPROPERTY(ReplicatedUsing = OnRep_Test) TArray<int>arr;

UFUNCTION() void OnRep_Test(TArray<int>prevArr);

And in RepNotify function OnRep_Test i’m expecting to see prevArr equals to arr before replication. But it isn’t.

Example:

1)Initialize array on server and client like this arr.Init(0, 5);. So if print this arr it will be 0 0 0 0 0.

2)Now generate new value one by one (when mouse click for example) on the server and print arrays in RepNotify

My results:

// Change first item

7 0 0 0 0 ← arr(replicated as expected)

0 0 0 0 0 ← prevArr (okey, all previous values was 0)

// Change second item

7 3 0 0 0 ← arr(replicated as expected)

0 0 0 0 0 ← prevArr (why first item not 7??)

// Change third item

7 3 5 0 0 ← arr(replicated as expected)

0 0 0 0 0 ← prevArr (should be 7 3 0 0 0)

// Change first item again

1 3 5 0 0 ← arr(replicated as expected)

7 0 0 0 0 ← prevArr (now first item is correct, but others still 0)

Is it expected behaviour of RepNotify or bug?

Hey iLef,

I’ve attempted to reproduce your issue, but I’m not seeing the same results on my end, so it’s possible that I’m overlooking something. Would you mind sharing the full code that you are using for this so we can ensure that we are on the same page?

Hello Sean Flint,

Sure, here is my test code: link text
For test i’m pressing Fire action on the server and call UpdateArray() method. Then on client you will see AddOnScreenDebugMessage with two arrays (old and new).

Hey iLef,

So I’ve set this up in a slightly different way and got it working.

I’ll provide you with my code files so you can take a closer look and get a better idea of how to set it up, but at this time I do not believe that this is a bug.

Basically, TestActor contains the necessary functionality for creating and replicating the array, and then SCharacter spawns test actor and then uses an input to call a server function that generates a new array. TestActor prints both the old and current array, and they matched up as expected.

Have a great day!

link text

Hey Sean,

Thank you for your answer. As workaround i use the same method :slight_smile:
But i was expecting that i can avoid to cache old array and use old array from RepNotify function argument.

I agree with you, looks like this is not a bug.

Anyway thank you for your help!