demo.Loop

demo.Loop

#Overview

name: demo.Loop

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of demo.Loop is to control the behavior of replay playback in Unreal Engine 5’s demo system. Specifically, it determines whether a replay should loop back to the beginning when it reaches the end or stop playback entirely.

This setting variable is primarily used by the demo system, which is part of Unreal Engine’s networking and replay functionality. Based on the callsites, it’s clear that this variable is utilized in the Engine module, specifically within the DemoNetDriver class.

The value of this variable is set as a console variable (CVar) with an initial value of 0. It can be changed at runtime through console commands or programmatically.

The associated variable CVarLoopDemo interacts directly with demo.Loop. They share the same value and purpose, with CVarLoopDemo being the C++ representation of the console variable.

Developers must be aware that:

  1. Setting this variable to 1 will cause the replay to loop continuously.
  2. Setting it to 0 (default) will stop the replay when it reaches the end.
  3. This setting affects the behavior of the TickDemoPlayback function in the UDemoNetDriver class.

Best practices when using this variable include:

  1. Consider the intended user experience when deciding whether to loop replays or not.
  2. Be mindful of potential performance implications of continuous looping, especially for long replays.
  3. Ensure that any game logic depending on replay end is compatible with the looping behavior when enabled.

Regarding the associated variable CVarLoopDemo:

When working with CVarLoopDemo, it’s important to remember that changes to this variable will immediately affect the behavior of ongoing replay playbacks. Therefore, it should be modified with caution, especially in live environments.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/DemoNetDriver.cpp:64

Scope: file

Source code excerpt:

static TAutoConsoleVariable<float> CVarDemoCullDistanceOverride( TEXT( "demo.CullDistanceOverride" ), 0.0f, TEXT( "If > 0, will represent distance from any viewer where actors will stop being recorded." ) );
static TAutoConsoleVariable<float> CVarDemoRecordHzWhenNotRelevant( TEXT( "demo.RecordHzWhenNotRelevant" ), 2.0f, TEXT( "Record at this frequency when actor is not relevant." ) );
static TAutoConsoleVariable<int32> CVarLoopDemo(TEXT("demo.Loop"), 0, TEXT("<1> : play replay from beginning once it reaches the end / <0> : stop replay at the end"));
static TAutoConsoleVariable<int32> CVarDemoFastForwardIgnoreRPCs( TEXT( "demo.FastForwardIgnoreRPCs" ), 1, TEXT( "If true, RPCs will be discarded during playback fast forward." ) );
static TAutoConsoleVariable<int32> CVarDemoLateActorDormancyCheck(TEXT("demo.LateActorDormancyCheck"), 1, TEXT("If true, check if an actor should become dormant as late as possible- when serializing it to the demo archive."));

static TAutoConsoleVariable<int32> CVarDemoJumpToEndOfLiveReplay(TEXT("demo.JumpToEndOfLiveReplay"), 1, TEXT("If true, fast forward to a few seconds before the end when starting playback, if the replay is still being recorded."));
static TAutoConsoleVariable<int32> CVarDemoInternalPauseChannels(TEXT("demo.InternalPauseChannels"), 1, TEXT("If true, run standard logic for PauseChannels rather than letting the game handle it via FOnPauseChannelsDelegate."));

#Associated Variable and Callsites

This variable is associated with another variable named CVarLoopDemo. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/DemoNetDriver.cpp:64

Scope: file

Source code excerpt:

static TAutoConsoleVariable<float> CVarDemoCullDistanceOverride( TEXT( "demo.CullDistanceOverride" ), 0.0f, TEXT( "If > 0, will represent distance from any viewer where actors will stop being recorded." ) );
static TAutoConsoleVariable<float> CVarDemoRecordHzWhenNotRelevant( TEXT( "demo.RecordHzWhenNotRelevant" ), 2.0f, TEXT( "Record at this frequency when actor is not relevant." ) );
static TAutoConsoleVariable<int32> CVarLoopDemo(TEXT("demo.Loop"), 0, TEXT("<1> : play replay from beginning once it reaches the end / <0> : stop replay at the end"));
static TAutoConsoleVariable<int32> CVarDemoFastForwardIgnoreRPCs( TEXT( "demo.FastForwardIgnoreRPCs" ), 1, TEXT( "If true, RPCs will be discarded during playback fast forward." ) );
static TAutoConsoleVariable<int32> CVarDemoLateActorDormancyCheck(TEXT("demo.LateActorDormancyCheck"), 1, TEXT("If true, check if an actor should become dormant as late as possible- when serializing it to the demo archive."));

static TAutoConsoleVariable<int32> CVarDemoJumpToEndOfLiveReplay(TEXT("demo.JumpToEndOfLiveReplay"), 1, TEXT("If true, fast forward to a few seconds before the end when starting playback, if the replay is still being recorded."));
static TAutoConsoleVariable<int32> CVarDemoInternalPauseChannels(TEXT("demo.InternalPauseChannels"), 1, TEXT("If true, run standard logic for PauseChannels rather than letting the game handle it via FOnPauseChannelsDelegate."));

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/DemoNetDriver.cpp:2884

Scope (from outer to inner):

file
function     void UDemoNetDriver::TickDemoPlayback

Source code excerpt:

				else
				{
					if (CVarLoopDemo.GetValueOnGameThread() > 0)
					{
						if (!LocalPlaylistTracker)
						{
							GotoTimeInSeconds(0.0f);
						}
						else if (LocalPlaylistTracker->IsOnLastReplay())