Giter Club home page Giter Club logo

ue-plugin-networktimesync's Introduction

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

ue-plugin-networktimesync's People

Contributors

erlite avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.