Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Ping Pong

TheYellowArchitect edited this page Feb 8, 2021 · 10 revisions

Ping measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source. You probably want to be able to see your Ping in the game. Show it to the player, or use it for the game's mechanics.

First of all, with a networkObject (make sure it is not null!), access the Networker, and register to the onPingPong event!

networkObject.Networker.onPingPong += OnPingPong;


public void OnPingPong(double ping, NetWorker player)
{
    Debug.Log("Ping: " + (int) ping);
}

And somewhere, call Ping()!

networkObject.Networker.Ping();

Advanced Ping

To ping each player, you have to check if the client is bound, not null, etc etc
Maybe you want to add a ping timer atop of that?
Here is an example, building atop of the above! (ctrl+f ping)

Fluctuating Ping

Locally testing your game, you should have 0 ping. There are 2 ways to simulate different pings

  1. Forge's Internal Functions
  2. This software which can simulate lag, packet drops etc etc (it's pretty neat!)

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks
Clone this wiki locally