HomeGuides
HomeGuidesLearn about the Immerse SDK installerLog In

πŸ“˜

This feature requires the Immerse SDK Enterprise Edition

This is different to the free Immerse SDK. Contact [email protected] if you require access.

Understand the difference between the Free and Enterprise SDK

Knowing the current time on the server, which is shared between all users, allows a developer to easily synchronize events or animations without having to even send a message. It is however important to understand the different types of clock that are available.

Types of Clock

Each type of clock is listed below, with a brief description. It is important to use the right clock when attempting to make use of the server time.

πŸ“˜

For most cases, the Relative Clock will be the preferred choice.

Description
Global ClockReturns the time since the session started
Recording ClockReturns the time since recording started
Playback ClockWhen playing back a recording, this will return the current position of the playback head
Relative ClockWhen playing back a recording, this will return the Playback Clock. Otherwise it will return the Global Clock instead.

Smoothing

Each of the clock values are only updated when a message is received (roughly every 0.2 seconds). If you tried to use any of these values to drive something such as an animation, you would get very choppy playback. To solve this problem, we have added 'smoothed' variants of each clock, where we use Unity's unscaled time value to extrapolate, based on the time in which the last clock update was received.

Example

Below is an example script which, when applied to a game object, will rotate in time with the server clock. This means that all users will see the object synchronized to the same rotation. Any newly joining users will also see it at the same rotation.

using ImmerseSDK.PlatformServices.Multiuser;
using UnityEngine;

/// <summary>
/// Rotates a transform using the ghost clock to determine it's rotation
/// </summary>
public class ClockDemo : MonoBehaviour
{
    [Tooltip("How fast it should rotate")] 
    public float Speed = 10f;

    [Tooltip("If this should used smoothed time")]
    public bool Smoothed;

    private void Update()
    {
        // Do not update when not connected
        if (Networking.Status != ConnectionStatus.Connected)
        {
            return;
        }
        
        var time = Smoothed
            ? Networking.Client.Time.RelativeClockSmoothed
            : Networking.Client.Time.RelativeClock;
            
        transform.localEulerAngles = new Vector3(0, time * Speed, 0);
    }
}