Skip to content

A simple Unreal Engine subsystem to provide a more accurate server world time to clients.

License

Notifications You must be signed in to change notification settings

Erlite/NetworkTimeSync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetworkTimeSync

A simple C++ (and Blueprint compatible) plugin that aims to provide a more accurate server world time to clients.

Installation

Simply place the contents of this repository in a Plugins/NetworkTimeSync/ folder of your project.

You must then enable the plugin in your Project Settings, and in your ProjectName.Build.cs file.

PublicDependencyModuleNames.Add("NetworkTimeSync");

Once compiled and enabled, simply add the UNetworkTimeSyncComponent to your Player Controller. This component will be in charge of synchronizing network time, every 10 seconds by default.

image

Usage

The NetworkTimeSubsystem is a GameInstance subsystem, which will contain the latest server world time. You can access it in C++ via the GameInstance, or by using the static provided:

// via the GameInstance
if (UGameInstance* GI = GetWorld()->GetGameInstance())
{
  UNetworkTimeSubsystem* NetworkTime = GI->GetSubsystem<UNetworkTimeSubsystem>();
  const float ServerTime = NetworkTime->GetServerWorldTime();
}

// or, you can use the static with a world context object.
UNetworkTimeSubsystem* NetworkTime = UNetworkTimeSubsystem::Get(this);
// May return null with an invalid world context object.
if (NetworkTime)
{
  const float ServerTime = NetworkTime->GetServerWorldTime();
}

For Blueprints, you can simply access it via the generated node:

image

All you have to do is replace any calls to the GameState's GetServerWorldTimeSeconds() function with this one.

Configuration

You can configure the synchronization interval in your Project Settings.

By default, it will reliably synchronize every ten seconds. You may want to increase or decrease that interval based on your preference.

Warning: if you decrease the interval for it to synchronize very often, enable Use Unreliable RPCs to avoid saturating your bandwidth with RPCs.

image

About

A simple Unreal Engine subsystem to provide a more accurate server world time to clients.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published