x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.13
Tags:
more ▼

asked Nov 07 '16 at 09:50 PM in Bug Reports

avatar image

iLef
11 2 4 7

avatar image Sean L ♦♦ STAFF Nov 08 '16 at 06:54 PM

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?

avatar image iLef Nov 08 '16 at 09:27 PM

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).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Nov 15 '16 at 09:37 PM

avatar image

Sean L ♦♦ STAFF
43.5k 485 152 442

avatar image iLef Nov 22 '16 at 08:11 PM

Hey Sean,

Thank you for your answer. As workaround i use the same method :) 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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question