DefaultGravityZ
DefaultGravityZ
#Overview
name: DefaultGravityZ
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 10
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of DefaultGravityZ is to define the default gravity value in the Z-axis (vertical direction) for the physics simulation in Unreal Engine 5. This setting is crucial for the physics and movement systems within the engine.
DefaultGravityZ is primarily used by the physics and movement systems in Unreal Engine. It is referenced in various subsystems and modules, including:
- Animation system (AnimationEditorPreviewScene, AnimPhysicsSolver)
- Physics Asset Editor
- World Settings
- Movement Components
- Physics Volumes
- General World physics
The value of DefaultGravityZ is typically set in the UPhysicsSettingsCore class, which is part of the PhysicsCore module. It has a default value of -980.f (negative because gravity pulls downward in UE’s coordinate system).
Other variables that interact with DefaultGravityZ include:
- WorldGravityZ in AWorldSettings
- GlobalGravityZ in AWorldSettings
- GravityScale in various components
Developers should be aware of the following when using this variable:
- It can be overridden at different levels (e.g., World Settings, Physics Volumes)
- The value is in cm/s^2, not m/s^2 as in real-world physics
- It affects all physics simulations unless explicitly overridden
Best practices when using DefaultGravityZ:
- Use the UPhysicsSettings::Get()->DefaultGravityZ to access the value, rather than hardcoding it
- Consider performance implications when changing gravity dynamically
- Be consistent with gravity changes across related systems (e.g., particle systems, character movement)
- Use the World Settings or Physics Volumes to create localized gravity changes rather than modifying the default value
- When creating realistic environments, remember to adjust the value to match the scale of your world (e.g., if your world is scaled differently from real-world measurements)
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:3157, section: [/Script/Engine.PhysicsSettings]
- INI Section:
/Script/Engine.PhysicsSettings
- Raw value:
-980.0
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/Persona/Private/AnimationEditorPreviewScene.cpp:1104
Scope (from outer to inner):
file
function void FAnimationEditorPreviewScene::SetGravityScale
Source code excerpt:
UWorld* World = GetWorld();
AWorldSettings* Setting = World->GetWorldSettings();
Setting->WorldGravityZ = UPhysicsSettings::Get()->DefaultGravityZ*RealGravityScale;
Setting->bWorldGravitySet = true;
}
float FAnimationEditorPreviewScene::GetGravityScale() const
{
return GravityScale;
#Loc: <Workspace>/Engine/Source/Editor/PhysicsAssetEditor/Private/PhysicsAssetEditorEditMode.cpp:505
Scope (from outer to inner):
file
function void FPhysicsAssetEditorEditMode::Tick
Source code excerpt:
UWorld* World = SharedData->PreviewScene.Pin()->GetWorld();
AWorldSettings* Setting = World->GetWorldSettings();
Setting->WorldGravityZ = SharedData->bNoGravitySimulation ? 0.0f : (SharedData->EditorOptions->bUseGravityOverride ? SharedData->EditorOptions->GravityOverrideZ : (UPhysicsSettings::Get()->DefaultGravityZ * SharedData->EditorOptions->GravScale));
Setting->bWorldGravitySet = true;
// We back up the transforms array now
SharedData->EditorSkelComp->AnimationSpaceBases = SharedData->EditorSkelComp->GetComponentSpaceTransforms();
// When using the World solver, we must specify how much of the solver output gets blended into the animated mesh pose
// When using other solvers in PhAT, we don't want SetPhysicsBlendWeight function to re-enale the main solver physics
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/WorldSettings.h:532
Scope: file
Source code excerpt:
uint8 bEnableWorldOriginRebasing:1;
/** if set to true, when we call GetGravityZ we assume WorldGravityZ has already been initialized and skip the lookup of DefaultGravityZ and GlobalGravityZ */
UPROPERTY(transient)
uint8 bWorldGravitySet:1;
/** If set to true we will use GlobalGravityZ instead of project setting DefaultGravityZ */
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta=(DisplayName = "Override World Gravity"), Category = Physics)
uint8 bGlobalGravitySet:1;
/**
* Causes the BSP build to generate as few sections as possible.
* This is useful when you need to reduce draw calls but can reduce texture streaming efficiency and effective lightmap resolution.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Animation/AnimPhysicsSolver.cpp:850
Scope (from outer to inner):
file
function void FAnimPhys::InitializeBodyVelocity
Source code excerpt:
InBody->AngularMomentum *= AngularDampingLeftOver;
FVector Force = InBody->bUseGravityOverride ? (InBody->GravityOverride * InBody->Mass) : (GravityDirection * FMath::Abs(UPhysicsSettings::Get()->DefaultGravityZ) * InBody->Mass * InBody->GravityScale);
FVector Torque(0.0f, 0.0f, 0.0f);
// Add wind forces
if(InBody->bWindEnabled)
{
// Multiplier for wind forces, we have a similar arbitrary scale in cloth wind, doing similar here
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/MovementComponent.cpp:371
Scope (from outer to inner):
file
function float UMovementComponent::GetGravityZ
Source code excerpt:
{
APhysicsVolume* PhysicsVolume = GetPhysicsVolume();
return PhysicsVolume ? PhysicsVolume->GetGravityZ() : UPhysicsSettings::Get()->DefaultGravityZ;
}
void UMovementComponent::HandleImpact(const FHitResult& Hit, float TimeSlice, const FVector& MoveDelta)
{
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsVolume.cpp:117
Scope (from outer to inner):
file
function float APhysicsVolume::GetGravityZ
Source code excerpt:
{
const UWorld* MyWorld = GetWorld();
return MyWorld ? MyWorld->GetGravityZ() : UPhysicsSettings::Get()->DefaultGravityZ;
}
void APhysicsVolume::ActorEnteredVolume(AActor* Other) {}
void APhysicsVolume::ActorLeavingVolume(AActor* Other) {}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/World.cpp:6033
Scope (from outer to inner):
file
function float UWorld::GetDefaultGravityZ
Source code excerpt:
{
UPhysicsSettings * PhysSetting = UPhysicsSettings::Get();
return (PhysSetting != NULL) ? PhysSetting->DefaultGravityZ : 0.f;
}
/** This is our global function for retrieving the current MapName **/
ENGINE_API const FString GetMapNameStatic()
{
FString Retval;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/WorldSettings.cpp:238
Scope (from outer to inner):
file
function float AWorldSettings::GetGravityZ
Source code excerpt:
// try to initialize cached value
AWorldSettings* const MutableThis = const_cast<AWorldSettings*>(this);
MutableThis->WorldGravityZ = bGlobalGravitySet ? GlobalGravityZ : UPhysicsSettings::Get()->DefaultGravityZ; //allows us to override DefaultGravityZ
}
return WorldGravityZ;
}
#if WITH_EDITOR
#Loc: <Workspace>/Engine/Source/Runtime/PhysicsCore/Private/PhysicsSettingsCore.cpp:26
Scope (from outer to inner):
file
function UPhysicsSettingsCore::UPhysicsSettingsCore
Source code excerpt:
UPhysicsSettingsCore::UPhysicsSettingsCore(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, DefaultGravityZ(-980.f)
, DefaultTerminalVelocity(4000.f)
, DefaultFluidFriction(0.3f)
, SimulateScratchMemorySize(262144)
, RagdollAggregateThreshold(4)
, TriangleMeshTriangleMinAreaThreshold(5.0f)
, bEnableEnhancedDeterminism(false)
#Loc: <Workspace>/Engine/Source/Runtime/PhysicsCore/Public/PhysicsSettingsCore.h:22
Scope (from outer to inner):
file
class class UPhysicsSettingsCore: public UDeveloperSettings
Source code excerpt:
/** Default gravity. */
UPROPERTY(config,EditAnywhere,Category = Constants)
float DefaultGravityZ;
/** Default terminal velocity for Physics Volumes. */
UPROPERTY(config,EditAnywhere,Category = Constants)
float DefaultTerminalVelocity;
/** Default fluid friction for Physics Volumes. */