Server/Client Timers

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
43
unrealdev.net
I know what I need to do, but I'm not quite sure how to do it. I'll try to explain as best I can.

.5 second timer
{
do code only on server/host of game
replicate/update variables to clients
}

.1 second timer
{
do this code on all machines, using variables from server
}

That is it really. It's for my rockets. Every half second the server calculates the changes and tells the clients "fly here". Every .1 seconds the rockets figure out by themselves how to fly there (which should be the same on all clients since they are all using the same variables in the same calculations). I can't quite figure out how to tell the code that "this should be done every half second and only on the server" and "this should be done every tenth of a second on all machines". Anyone know how to do that?
 

Bytekeeper

Last of the Brunnen G
Jul 15, 2001
181
0
0
Germany
Visit site
make something like:

int count;

simulated event beginplay()
{
settimer( 0.1, true );
}

simulated event Timer()
{
count= ( count + 1 ) % 5;
if ( !count && role == role_authority )
{
// Called on server only
}
// Code which every machine should do
}
 

SoSilencer

Harry Goz (1932 - 2003)
Nov 27, 2000
834
0
0
43
unrealdev.net
That's kinda what I'm doing now but it's not working right. It is all in a "function Timer()", does it need to be "simulated event Timer()" instead? What is the difference between those two?

I think one of my problems is that the rockets change physics mode. They start in PHYS_Falling when the rockets are ejected from the gun. About a half second later the rockets ignite and switch to PHYS_Projectile, only to run out of gas about 7 seconds later and switch back to PHYS_Faling. I can't seem to get the physics to replicate (or anything else for that matter) so the rockets just fall forward out of the gun and that's it.
 

Bytekeeper

Last of the Brunnen G
Jul 15, 2001
181
0
0
Germany
Visit site
Simulated means, that the function can be called on the client. For events etc. to be called clientside your actor has to be role_simulatedproxy, so check if it is too.
If you call a nonsimulated function clientside it will not be processed, so remember, every actor < ROLE_AutonomousProxy needs a simulated before the function call if you want it to be called clientside.
Hmm, the physics are only replicated once to the client, and that's when you spawn a new rocket.

You could set bSimFall= true, that would replicate Velocity, Accelerarion, bBounce and Physics to the client.
Or you let the client decide on it's own when to set the physics by replicating gas etc.