Hey there,
I managed to make my custom AActor-extending actor do what I needed on its Tick(). now I want to replicate a var across the network.
I followed ShooterGame’s example and tried adding the GetReplicationList() function. it however, wasn’t defined in any header file, just implemented in the cpp files.
so I copied the function and changed it a little bit, adapting the naming pattern to my own class. however DOREP() throws me an error.
here’s how it looks:
of course CurrentTime is a var defined in my header files and I’m using it in my code without problems.
so I don’t understand why it doesn’t work. if I comment out line 70 it works again. so how do I do this correctly?
thanks
ok I’m still trying to replicate a simple variable. I now tried the ReplicatedUsing specifier. here’s what I did:
link text
of course the part of the GetReplicationList() function where I replicate my CurrentTime var is commented out because of the error I mentioned in the original post. And apparently, if the var isn’t addded to the GetReplicationList() it never does get replicated.
the result: the server keeps logging “*UpdateTime X” (where X is the ongoing world seconds), but the client gets nothing on its log
so how do I replicate a variable?
Unfortunately the link text is not working for me.
You are correct - native variables must be added to the replication list via GetReplicationList. The difference between the ‘replicated’ and ‘replicatedUsing’ keywords only determines whether a RepNotify function is called on the client when the replication happens. GetReplicationList is always required.
The error in your original post looks like DOREP is not defined. Where are you defining the GetReplicationList function? Is Net/UnrealNetwork.h included? The syntax of the DOREP line looks right to me.
Also just to note, GetReplicationList is not declared in any user headers. It is declared as part of the generated code that Unreal Header Tool creates.
Also, if you want to continuously replicate the property (e.g, send the property to clients every time it changes), you don’t want to do it inside of a RepFlags.bNetInitial check. bNetInitial is only true on the initial bunch, so in your example, if it compiled, would only replicate one time and then stop. Just remove the if statement and always call DOREP.
Just to be clear, make sure to include UnrealNetwork.h in the .cpp you are implementing GetReplicationList in. Then your DOREP call should work.One of these two lines should do it:
#include "Net/UnrealNetwork.h"
#include "Runtime/Engine/Public/Net/UnrealNetwork.h"
yes, that works!
“Net/UnrealNetwork.h” did the trick.
now I get some weirdnesses in the way my function is executed on the client, but that’s most likely something wrong on my own code.
thanks again!
I guess the c++ part where I need to include header files as opposed to having everything pre-integrated (ala UE3) is where I got stuck. it’s only the second time I ever need to include other headers (first time was for DrawDebugLine) so I’m still not used to the idea of it.
I’ll be sure to include Net and/or UnrealNetwork.h and I’ll try again.
as for bNetInitial, I’m still not an expert in UE networking but in this case I’m only wanting to replicate my var to clients when they join the game and then let them simulate it on their own - this specific class is meant to exist as the basis of a Day/Night and Time system, and so I want new joined players to get “what time it is” when they join, and let the time cycle go on client-side.
in any case, thanks for clearing it up!
Ahh yeah, in that case, you do want the bNetInitial check.
good to know I’m not that lost in terms of networking. thanks!