Adjust world gravity at runtime?

Hey, I had a similar situation where it required me to change world gravity at real-time. After searching through, one way to change the global gravity is by using C++. By default UE4 uses ‘Default Gravity Z’ found in Project Settings->Engine->Physics. In order to change the default gravity to user customed gravity, we can make use of WorldSettings.h class in your actor class.
According to the class:

with ‘bGlobalGravitySet’ to true and setting the GlobalGravityZ=‘YourFloatGravity’.

One small way to implement would be:
AWorldSettings* MyWorldSetting=GetWorldSettings();
MyWorldSetting->bGlobalGravitySet=true;
MyWorldSetting->GlobalGravityZ = 900.f;

Hope this helps.

3 Likes