PhysicErrorCorrection

PhysicErrorCorrection

#Overview

name: PhysicErrorCorrection

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of PhysicErrorCorrection is to handle error correction data for replicating simulated physics, specifically for rigid bodies in networked gameplay scenarios. This setting variable is crucial for maintaining consistent and smooth physics simulation across different clients and the server in a networked game environment.

PhysicErrorCorrection is primarily used by the Physics Replication system within Unreal Engine’s physics simulation module. Based on the callsites, it’s clear that this variable is utilized in the PhysicsEngine subsystem, particularly in the PhysicsReplication component.

The value of this variable is set in the UPhysicsSettings class, which is a configuration class for physics-related settings in Unreal Engine. It’s defined as a property that can be edited in the project settings, allowing developers to fine-tune the error correction parameters.

This variable interacts closely with the FPhysicsReplicationAsync class, which is set up using the PhysicErrorCorrection values. It’s also used in the FPhysicsReplication::OnTick function, where it’s passed to the PrepareAsyncData_External and ApplyRigidBodyState functions.

Developers must be aware that this variable significantly impacts the accuracy and smoothness of replicated physics in multiplayer games. Improper configuration can lead to visual discrepancies between clients or unnatural movement of physics objects.

Best practices when using this variable include:

  1. Carefully tuning the error correction parameters based on the specific needs of your game, considering factors like network latency and the types of physics interactions in your game.
  2. Testing the settings thoroughly in various network conditions to ensure smooth and consistent physics behavior across different clients.
  3. Being mindful of the performance impact, as more aggressive error correction can potentially increase network traffic and processing overhead.
  4. Considering the interplay between this setting and other network-related settings, such as network update frequency and interpolation settings.
  5. Documenting any custom configurations for your project to ensure consistency across the development team and for future reference.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:325, section: [/Script/Engine.PhysicsSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/PhysicsEngine/PhysicsSettings.h:151

Scope (from outer to inner):

file
class        class UPhysicsSettings : public UPhysicsSettingsCore

Source code excerpt:

	/** Error correction data for replicating simulated physics (rigid bodies) */
	UPROPERTY(config, EditAnywhere, Category = Replication)
	FRigidBodyErrorCorrection PhysicErrorCorrection;

	UPROPERTY(config)
	TEnumAsByte<ESettingsLockedAxis::Type> LockedAxis_DEPRECATED;

	/** Useful for constraining all objects in the world, for example if you are making a 2D game using 3D environments.*/
	UPROPERTY(config, EditAnywhere, Category = Simulation)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsReplication.cpp:237

Scope (from outer to inner):

file
function     FPhysicsReplication::FPhysicsReplication

Source code excerpt:

	{
		PhysicsReplicationAsync = Solver->CreateAndRegisterSimCallbackObject_External<FPhysicsReplicationAsync>();
		PhysicsReplicationAsync->Setup(UPhysicsSettings::Get()->PhysicErrorCorrection);
	}
}

FPhysicsReplication::~FPhysicsReplication()
{
	if (PhysicsReplicationAsync)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsReplication.cpp:371

Scope (from outer to inner):

file
function     void FPhysicsReplication::OnTick

Source code excerpt:

	}

	const FRigidBodyErrorCorrection& PhysicErrorCorrection = UPhysicsSettings::Get()->PhysicErrorCorrection;
	if (PhysicsReplicationAsync)
	{
		PrepareAsyncData_External(PhysicErrorCorrection);
	}

	// Get the ping between this PC & the server
	const float LocalPing = GetLocalPing();

	// BodyInstance replication flow, deprecated

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsReplication.cpp:412

Scope (from outer to inner):

file
function     void FPhysicsReplication::OnTick

Source code excerpt:

							{
								const int32 LocalFrame = PhysicsTarget.ServerFrame - LocalFrameOffset;
								const bool bRestoredState = ApplyRigidBodyState(DeltaSeconds, BI, PhysicsTarget, PhysicErrorCorrection, PingSecondsOneWay, LocalFrame, 0);

								// Need to update the component to match new position.
								if (PhysicsReplicationCVars::SkipSkeletalRepOptimization == 0 || Cast<USkeletalMeshComponent>(PrimComp) == nullptr)	//simulated skeletal mesh does its own polling of physics results so we don't need to call this as it'll happen at the end of the physics sim
								{
									PrimComp->SyncComponentToRBPhysics();
								}