This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Working With Time via API

There is a set of "times" that you can get via API using different classes, so you might get confused - which one to use and when. The goal of this small article is to get rid of the ambiguity.

Time#

Game.Time - time of the game. This method is the least accurate, based on internal Engine::time it ignores spikes and freezes. It is suitable for creating games. Moreover, you can change the speed of this timer using Game.Scale and Game.Enabled. That is, after a game pause, the game state will remain where it was before the pause, without shifting far away - animations, particles, etc. will resume from the same position.

Stopwatch.GetTimestamp() method (from the standard System.Diagnostics module) is the most accurate and closest to wall-clock time. It returns seconds as a double precision, allowing operation with microseconds/nanoseconds. It ignores spikes and freezes. Can be used for any application independent time calculations.

In case you don't need time accuracy that high, you can simply use the standard and convenient DateTime.Now property.

Unigine.Plugins.Syncker.Syncker.Time property returns seconds as a double value. Based on Time, it also ignores spikes but may be shifted forward or backward in case of synchronization disruption between the Master and Slaves. Should be used for critical animations and logic synchronized through Syncker mechanisms.

Unigine.Plugins.IG.Manager.InterpolationTime property can also be shifted forward or backward in case of disruption of IG-Host synchronization. Between host-frames, it uses Unigine.Plugins.Syncker.Syncker.Time, so it can also be shifted in case of disruption of Master-Slave synchronization. This is used only for interpolating motion of entities obtained with timestamps from the host.

Delta Time (a.k.a. IFps)#

With regards to game engines, Delta Time means the amount of time that has elapsed since the previous frame. In UNIGINE this thing is called Inverse FPS or shorter IFps. Similar to the times described above, there are several 'delta times' you can meet as well.

Engine.IFps - time spent to complete the last frame (time between the last frame and the current one). It returns seconds as a float value, so precision after the decimal point is not guaranteed. It is normal to deliberately ignore any spikes and freezes of the application. You can call Engine.StartFps() / Engine.StopFps() to ignore (exclude from being taken into account) a certain spike that you're going to make (e.g., process some heavy non-rendering tasks) or in case the application window is hidden.

Game.IFps - similar to Engine.IFps, it's the time between the last frame of the game and the current one (the time in seconds it took to complete the last frame). It is suitable for creating games. Usually this time is the same as the Engine's IFps, but you can change the scale of this timer using Game.Scale and even stop it for a while via Game.Enabled. After a game pause, the game state will remain where it was before the pause - animations/expression will continue from the same position and state, etc. Moreover, you can use Game.IFps to set your own IFps value when necessary.

Unigine.Plugins.Syncker.Syncker.IFps and Unigine.Plugins.IG.Manager.IFps properties will both give you the actual time difference between the last subsequent frames (previous and current), without an option to tweak or ignore anything. Should be used for critical animations and logic synchronization through Syncker mechanisms on different computers, without being afraid of sync disruption.

Last update: 2024-12-13
Build: ()