[Question] Changing VSync During Runtime Using Console or C++?

Dear Friends at Epic,

I’ve been thinking about my options menu lately, and I am confused about how to change VSync without requiring a restart.

there is the commandline for vsync
https://rocket.unrealengine.com/docs/ue4/INT/GettingStarted/Basics/CommandLineArguments/index.html#rendering

But is there a console command or C++ function to change VSync without requiring a game restart?

Rama

The recommended way to do so is via the game user settings system, e.g.:

GEngine->GameUserSettings->SetVSyncEnabled(true);
GEngine->GameUserSettings->ApplySettings();

The intended workflow is that you have a UI that modifies the settings on the GameUserSettings object and then calls ApplySettings to apply the changes. These settings will be saved and loaded to a game specific INI file (make sure to call SaveSettings() if you change them in code!)

Alternatively, if you care only about VSync, all you need to do is set a console variable. In general we don’t recommend setting console variables from code, but this one is safe to do so:

IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.VSync")); 
CVar->Set(IsVSyncEnabled());

Oh wow!

Game User Settings is exactly what I was looking for!

Thanks Nick!

For others reading this, check out GameUserSettings.h !

Thanks for the Code Nick!

Rama

I’m currently unsure as to whether you can change it at runtime (there are also no console commands to do so), however the common technique is to use the ini configuration files. When the user changes their settings, update the respective ini file, so that when the game runs the next time, it will run with the desired setting.

Yup, but I want to update VSync during runtime,

as in most games I never get a “You must restart to get effects of changed VSync” message

so I assume it can be done without requiring a restart

it’s a relatively minor point

Mainly I need to know if it is possible so I DONT have to tell the user to restart

:slight_smile:

RAma