ListTimers

ListTimers

#Overview

name: ListTimers

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of ListTimers is to provide a debugging tool for developers to inspect and output information about all currently set timers in the Unreal Engine’s timer system. This functionality is primarily used for diagnostics and debugging purposes within the engine’s timer management system.

ListTimers is part of the Unreal Engine’s core timer management system, which is located in the Engine module. Based on the callsites, it’s clear that this functionality is tightly integrated with the FTimerManager class, which is responsible for managing and executing timers in the engine.

The value of this variable is not set directly, as ListTimers is actually a console command rather than a variable. It’s registered as a console command using FAutoConsoleCommandWithWorld, which allows developers to invoke it from the game’s console.

ListTimers interacts with the FTimerManager class, specifically its ListTimers() method. When the console command is invoked, it calls the ListTimers() method of the current World’s TimerManager.

Developers should be aware that:

  1. This command is intended for debugging purposes and should not be relied upon for gameplay logic.
  2. It’s only available when called from the game thread, as indicated by the check(IsInGameThread()) assertion.
  3. The output is sent to the log, so developers need to check the appropriate log files or console output to see the results.

Best practices when using ListTimers include:

  1. Use it during development and testing phases to verify timer behavior.
  2. Be cautious about using it in shipping builds, as it may impact performance if called frequently.
  3. Consider creating a development-only wrapper around this functionality if you need to use it in game code, to ensure it’s not accidentally left in release builds.
  4. Remember that it provides a snapshot of the current timer state, so repeated calls may be necessary to track changes over time.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TimerManager.cpp:1164

Scope: file

Source code excerpt:

// Register ListTimers console command, needs a World context
FAutoConsoleCommandWithWorld ListTimersConsoleCommand(
	TEXT("ListTimers"),
	TEXT(""),
	FConsoleCommandWithWorldDelegate::CreateStatic(OnListTimers)
	);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TimerManager.cpp:1033

Scope (from outer to inner):

file
function     void FTimerManager::ListTimers

Source code excerpt:

}

void FTimerManager::ListTimers() const
{
	// not currently threadsafe
	check(IsInGameThread());

	TArray<const FTimerData*> ValidActiveTimers;
	ValidActiveTimers.Reserve(ActiveTimerHeap.Num());

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/TimerManager.cpp:1153

Scope: file

Source code excerpt:



// Handler for ListTimers console command
static void OnListTimers(UWorld* World)
{
	if(World != nullptr)
	{
		World->GetTimerManager().ListTimers();
	}
}

// Register ListTimers console command, needs a World context
FAutoConsoleCommandWithWorld ListTimersConsoleCommand(
	TEXT("ListTimers"),
	TEXT(""),
	FConsoleCommandWithWorldDelegate::CreateStatic(OnListTimers)
	);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/TimerManager.h:441

Scope (from outer to inner):

file
class        class FTimerManager : public FNoncopyable

Source code excerpt:


	/** Debug command to output info on all timers currently set to the log. */
	ENGINE_API void ListTimers() const;

private:
	ENGINE_API void SetGameInstance(UGameInstance* InGameInstance);

// This should be private, but needs to be public for testing.
public: