AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged

AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged

#Overview

name: AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged

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 AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged is to control whether server-initiated prediction keys are sent to the client as acknowledged in the Unreal Engine’s Gameplay Ability System.

This setting variable is primarily used in the Gameplay Abilities plugin, which is part of the Unreal Engine’s runtime modules. It specifically affects the prediction system within the Ability System, which is crucial for handling network gameplay and synchronization between client and server.

The value of this variable is set through a console variable (CVar) system. It’s initialized to 0 (false) by default, as seen in the source code. Developers can change this value at runtime using console commands or through configuration files.

The associated variable CVarReplicateServerKeysAsAcknowledgedValue directly interacts with AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged. They share the same value, with CVarReplicateServerKeysAsAcknowledgedValue being the actual integer storage for the setting.

Developers must be aware that:

  1. This setting was changed in UE 5.4.2. Prior to this version, server-initiated keys were sent as acknowledged, which could cause issues.
  2. Enabling this (setting to non-zero) may cause key hash collisions due to limited space based on the key value.
  3. When enabled, it allows server-initiated prediction keys to be sent as acknowledged to the client, which is generally not recommended.

Best practices when using this variable include:

  1. Keep it disabled (set to 0) unless there’s a specific need to change the behavior.
  2. If enabled, carefully monitor for potential key hash collisions or unexpected behavior in network gameplay.
  3. Use it in conjunction with proper logging and debugging to track prediction key behavior.

Regarding the associated variable CVarReplicateServerKeysAsAcknowledgedValue:

The purpose of CVarReplicateServerKeysAsAcknowledgedValue is to store the actual integer value for the AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged setting.

It’s used internally within the Gameplay Abilities plugin to check whether server-initiated keys should be replicated as acknowledged.

The value is set through the CVar system, initialized to 0 by default.

This variable directly interacts with AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged, acting as its storage.

Developers should be aware that this variable is used in conditional checks to determine the behavior of prediction key replication.

Best practices include using this variable for read-only purposes in most cases, and modifying it through the CVar system rather than directly.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/Runtime/GameplayAbilities/Source/GameplayAbilities/Private/GameplayPrediction.cpp:35

Scope (from outer to inner):

file
namespace    UE::AbilitySystem::Private

Source code excerpt:

	// Unfortunately, it also causes key hash collisions since there is limited space based on the key value.
	int32 CVarReplicateServerKeysAsAcknowledgedValue = 0;
	FAutoConsoleVariableRef CVarReplicateServerKeysAsAcknowledged(TEXT("AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged"), CVarReplicateServerKeysAsAcknowledgedValue,
		TEXT("Do we send server initiated keys as acknowledged to the client? Default false. Was true prior to UE5.4.2."));

	/**
	 * Given an FProperty Link (such as a UFunction's Properties, or a UStruct's Properties), find and return any linked FPredictionKeys.
	 * This is useful for determining if we're sending FPredictionKeys via RPC.
	 */

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Plugins/Runtime/GameplayAbilities/Source/GameplayAbilities/Private/GameplayPrediction.cpp:34

Scope (from outer to inner):

file
namespace    UE::AbilitySystem::Private

Source code excerpt:

	// Prior to UE5.4.2, we used to allow Server Initiated Replication Keys to be sent to the client as 'acknowledged' but that hardly makes sense.
	// Unfortunately, it also causes key hash collisions since there is limited space based on the key value.
	int32 CVarReplicateServerKeysAsAcknowledgedValue = 0;
	FAutoConsoleVariableRef CVarReplicateServerKeysAsAcknowledged(TEXT("AbilitySystem.PredictionKey.RepServerKeysAsAcknowledged"), CVarReplicateServerKeysAsAcknowledgedValue,
		TEXT("Do we send server initiated keys as acknowledged to the client? Default false. Was true prior to UE5.4.2."));

	/**
	 * Given an FProperty Link (such as a UFunction's Properties, or a UStruct's Properties), find and return any linked FPredictionKeys.
	 * This is useful for determining if we're sending FPredictionKeys via RPC.
	 */

#Loc: <Workspace>/Engine/Plugins/Runtime/GameplayAbilities/Source/GameplayAbilities/Private/GameplayPrediction.cpp:501

Scope (from outer to inner):

file
function     FScopedPredictionWindow::~FScopedPredictionWindow

Source code excerpt:

			{
				const bool bServerInitiatedKey = OwnerPtr->ScopedPredictionKey.IsServerInitiatedKey();
				const bool bAllowAckServerInitiatedKey = UE::AbilitySystem::Private::CVarReplicateServerKeysAsAcknowledgedValue > 0;
				if (!bServerInitiatedKey || bAllowAckServerInitiatedKey)
				{
					UE_CLOG(bServerInitiatedKey, LogAbilitySystem, Warning, TEXT("Replicating Server Initiated PredictionKey %s (this may stomp a client key leaving it unack'd). See CVarReplicateServerKeysAsAcknowledged"), *OwnerPtr->ScopedPredictionKey.ToString());
					UE_VLOG_UELOG(OwnerPtr->GetOwnerActor(), LogPredictionKey, Verbose, TEXT("Server: ReplicatePredictionKey %s"), *OwnerPtr->ScopedPredictionKey.ToString());
					OwnerPtr->ReplicatedPredictionKeyMap.ReplicatePredictionKey(OwnerPtr->ScopedPredictionKey);
				}