17#include "Misc/CommandLine.h"
18#include "GenericPlatform/GenericPlatformMisc.h"
19#include "Kismet/GameplayStatics.h"
20#include "GameFramework/GameUserSettings.h"
21#include "Misc/CoreDelegates.h"
22#include "Misc/CommandLine.h"
23#include "Misc/Parse.h"
25#include "Engine/Engine.h"
26#include "Engine/GameViewportClient.h"
27#include "UObject/ObjectPtr.h"
28#include "LandscapeSubsystem.h"
29#include "Engine/World.h"
30#include "Engine/GameInstance.h"
31#include "Kismet/GameplayStatics.h"
32#include "TimerManager.h"
35#include "RHIDefinitions.h"
36#include "Engine/Engine.h"
64 ULandscapeSubsystem* LandscapeSubsystem =
CurrentWorld->GetSubsystem<ULandscapeSubsystem>();
65 if (LandscapeSubsystem)
67 LandscapeSubsystem->PrioritizeGrassCreation(
true);
78 GEngine->Exec(World, TEXT(
"r.OptimizedWPO 1"));
80 GEngine->Exec(World, TEXT(
"g.TimeoutForBlockOnRenderFence 600000"));
81 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0"));
82 GEngine->Exec(World, TEXT(
"r.CustomDepth 0"));
100 if (FParse::Param(FCommandLine::Get(), TEXT(
"Fullscreen")))
104 else if (FParse::Param(FCommandLine::Get(), TEXT(
"WindowedFullscreen")))
117 Super::PostInitProperties();
119#if UE_BUILD_SHIPPING || UE_BUILD_DEVELOPMENT
129 return Cast<UAgrarsenseSettings>(UGameUserSettings::GetGameUserSettings());
134 Super::LoadSettings(bForceReload);
139 Super::ApplySettings(bCheckForCommandLineOverrides);
147 bool SettingsWereChanged =
false;
150 FString AntiAliasingString;
151 if (FParse::Value(FCommandLine::Get(), TEXT(
"-antialiasing="), AntiAliasingString))
154 int32 AntiAliasingInt;
155 if (AntiAliasingString.IsNumeric())
157 AntiAliasingInt = FCString::Atoi(*AntiAliasingString);
160 SettingsWereChanged =
true;
165 if (FParse::Param(FCommandLine::Get(), TEXT(
"-no-spectator-rendering")))
168 SettingsWereChanged =
true;
172 if (FParse::Param(FCommandLine::Get(), TEXT(
"-start-camerawindows-minimized")))
175 SettingsWereChanged =
true;
179 FString QualityLevelString;
180 if (FParse::Value(FCommandLine::Get(), TEXT(
"-quality-level="), QualityLevelString))
183 SettingsWereChanged =
true;
186 return SettingsWereChanged;
191 return FPlatformMisc::NumberOfWorkerThreadsToSpawn();
196 IConsoleVariable* ConsoleVariable = IConsoleManager::Get().FindConsoleVariable(*VariableName);
199 FString VariableValue = ConsoleVariable->GetString();
200 return VariableValue;
224 UGameUserSettings* UserSettings = GEngine->GetGameUserSettings();
227 UserSettings->SetFullscreenMode(WindowType);
228 UserSettings->ApplySettings(
false);
257 if (!GEngine || !World)
266 GEngine->Exec(World, TEXT(
"grass.enable 0"));
267 GEngine->Exec(World, TEXT(
"grass.FlushCache"));
271 GEngine->Exec(World, TEXT(
"grass.enable 1"));
290 if (GEngine && World)
296 GEngine->Exec(World, TEXT(
"r.Shadow.CSMCaching 1"));
300 GEngine->Exec(World, TEXT(
"r.Shadow.CSMCaching 0"));
314 if (InstanceRenderer)
330 if (GEngine && World)
332 MaxPixelsPerEdge = FMath::Clamp(MaxPixelsPerEdge, 0.1f, 10.0f);
334 FString Command = FString::Printf(TEXT(
"r.Nanite.MaxPixelsPerEdge %f"), MaxPixelsPerEdge);
335 GEngine->Exec(World, *Command);
353 FString BehaviourStringToLower = BehaviourString.ToLower();
355 if (BehaviourStringToLower ==
"auto")
359 else if (BehaviourStringToLower ==
"rigid")
363 else if (BehaviourStringToLower ==
"always")
367 else if (BehaviourStringToLower ==
"static")
401 if (GEngine || World)
404 if (RenderCustomDepthPass)
406 GEngine->Exec(World, TEXT(
"r.CustomDepth 3"));
410 GEngine->Exec(World, TEXT(
"r.CustomDepth 0"));
418 if (GEngine || World)
424 GEngine->Exec(World, TEXT(
"r.Shadow.Virtual.Enable 1"));
428 GEngine->Exec(World, TEXT(
"r.Shadow.Virtual.Enable 0"));
455 if (!GEngine || !World)
463 switch (AntiAliasingMethod)
466 ExecCommand = TEXT(
"r.AntiAliasingMethod 0");
470 ExecCommand = TEXT(
"r.AntiAliasingMethod 1");
474 ExecCommand = TEXT(
"r.AntiAliasingMethod 2");
480 ExecCommand = TEXT(
"r.AntiAliasingMethod 4");
487 GEngine->Exec(World, *ExecCommand);
500 if (GEngine && GEngine->GameViewport)
502 GEngine->GameViewport->bDisableWorldRendering = !enabled;
505 FString msg = FString::Printf(TEXT(
"World rendering: %s"), enabled ? TEXT(
"On") : TEXT(
"Off"));
536 FString Msg = FString::Printf(TEXT(
"Graphics settings: %s"), *QualityLevelString);
549 return GetFrameRateLimit();
554 SetFrameRateLimit(NewTargetFrameRate);
567 return UGameplayStatics::GetGlobalTimeDilation(World);
579 UGameplayStatics::SetGlobalTimeDilation(World, TimeDilation);
581 FString msg = FString::Printf(TEXT(
"Global time dilation: %f"), TimeDilation);
594 if (IsValid(Spectator))
611 if (IsValid(Spectator))
623 UGameplayStatics::SetGlobalTimeDilation(World, 0.0f);
624 UGameplayStatics::SetGamePaused(World,
true);
637 UGameplayStatics::SetGamePaused(World,
false);
659 FCoreDelegates::OnEndFrame.Remove(EndOfFrameHandle);
660 EndOfFrameHandle.Reset();
670 if (FramesToAdvance == 0)
725 FTimerHandle AdvanceTimeTimer;
726 World->GetTimerManager().SetTimer(AdvanceTimeTimer, FTimerDelegate::CreateLambda([
this]
733 }), TimeToAdvance,
false);
740 MapName = MapName.ToLower();
742 bool FoundMap =
false;
743 for (int32 i = 0; i <
MapNames.Num(); i++)
748 FString msg = FString::Printf(TEXT(
"Changing map to: %s"), *MapName);
758 FString msg = FString::Printf(TEXT(
"Couldn't find map: %s"), *MapName);
768 UGameplayStatics::OpenLevel(World, *Path, TRAVEL_Absolute);
817 SimulatorLog::Log(
"Graphics settings: Ray tracing not supported on this hardware.");
823 bool RayTracingSupported =
false;
826 IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT(
"r.RayTracing"));
827 if (CVar && CVar->GetInt() > 0 && GRHISupportsRayTracing)
829 RayTracingSupported =
true;
832#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION <= 3
836 if (!GDynamicRHI && GDynamicRHI->GetName() == FString(TEXT(
"D3D12")))
838 RayTracingSupported =
false;
844 return RayTracingSupported;
850 if (!World || !GEngine)
855 GEngine->Exec(World, TEXT(
"r.Lumen.HardwareRayTracing 1"));
856 GEngine->Exec(World, TEXT(
"r.RayTracing.Geometry 1"));
857 GEngine->Exec(World, TEXT(
"r.RayTracing.Shadows 1"));
858 GEngine->Exec(World, TEXT(
"r.RayTracing.Reflections 1"));
859 GEngine->Exec(World, TEXT(
"r.RayTracing.AmbientOcclusion 1"));
860 GEngine->Exec(World, TEXT(
"r.RayTracing.GlobalIllumination 1"));
861 GEngine->Exec(World, TEXT(
"r.RayTracing.Translucency 1"));
862 GEngine->Exec(World, TEXT(
"r.RayTracing.SkyLight 1"));
868 if (!World || !GEngine)
873 GEngine->Exec(World, TEXT(
"r.Lumen.HardwareRayTracing 0"));
874 GEngine->Exec(World, TEXT(
"r.RayTracing.Geometry 0"));
875 GEngine->Exec(World, TEXT(
"r.RayTracing.Shadows 0"));
876 GEngine->Exec(World, TEXT(
"r.RayTracing.Reflections 0"));
877 GEngine->Exec(World, TEXT(
"r.RayTracing.AmbientOcclusion 0"));
878 GEngine->Exec(World, TEXT(
"r.RayTracing.GlobalIllumination 0"));
879 GEngine->Exec(World, TEXT(
"r.RayTracing.Translucency 0"));
880 GEngine->Exec(World, TEXT(
"r.RayTracing.SkyLight 0"));
886 if (!World || !GEngine)
894 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 3"));
895 GEngine->Exec(World, TEXT(
"sg.ShadowQuality 3"));
896 GEngine->Exec(World, TEXT(
"sg.TextureQuality 4"));
897 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 4"));
898 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 4"));
900 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.03"));
901 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 1"));
902 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 2"));
903 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 1"));
904 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 64"));
905 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 8"));
906 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 2"));
907 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 1"));
908 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 7"));
909 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
910 GEngine->Exec(World, TEXT(
"r.ShadowQuality 5"));
911 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 1"));
912 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 2"));
913 GEngine->Exec(World, TEXT(
"r.DetailMode 2"));
914 GEngine->Exec(World, TEXT(
"foliage.DensityScale 1"));
915 GEngine->Exec(World, TEXT(
"grass.DensityScale 1"));
916 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0 "));
917 GEngine->Exec(World, TEXT(
"r.Shadow.RadiusThreshold 0.00"));
925 if (!World || !GEngine)
932 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 3"));
933 GEngine->Exec(World, TEXT(
"sg.TextureQuality 3"));
934 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 3"));
935 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 3"));
937 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.03"));
938 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 1"));
939 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 2"));
940 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 1"));
941 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 64"));
942 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 8"));
943 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 2"));
944 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 1"));
945 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 7"));
946 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
947 GEngine->Exec(World, TEXT(
"r.ShadowQuality 3"));
948 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 1"));
949 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 2"));
950 GEngine->Exec(World, TEXT(
"r.DetailMode 2"));
951 GEngine->Exec(World, TEXT(
"r.BloomQuality 4"));
952 GEngine->Exec(World, TEXT(
"foliage.DensityScale 1"));
953 GEngine->Exec(World, TEXT(
"grass.DensityScale 1"));
954 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0 "));
955 GEngine->Exec(World, TEXT(
"r.Shadow.RadiusThreshold 0.01"));
963 if (!World || !GEngine)
970 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 0"));
971 GEngine->Exec(World, TEXT(
"sg.ShadowQuality 0"));
972 GEngine->Exec(World, TEXT(
"sg.TextureQuality 0"));
973 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 0"));
974 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 0"));
976 GEngine->Exec(World, TEXT(
"r.DefaultFeature.MotionBlur 0"));
977 GEngine->Exec(World, TEXT(
"r.DefaultFeature.Bloom 0"));
978 GEngine->Exec(World, TEXT(
"r.DefaultFeature.AmbientOcclusion 0"));
979 GEngine->Exec(World, TEXT(
"r.DefaultFeature.AmbientOcclusionStaticFraction 0"));
980 GEngine->Exec(World, TEXT(
"r.HZBOcclusion 0"));
981 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.01"));
982 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 0"));
983 GEngine->Exec(World, TEXT(
"r.FinishCurrentFrame 0"));
984 GEngine->Exec(World, TEXT(
"r.MotionBlurQuality 0"));
985 GEngine->Exec(World, TEXT(
"r.BloomQuality 1"));
986 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 0"));
987 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 0"));
988 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 4"));
989 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 4"));
990 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 0"));
991 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 0"));
992 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 0"));
993 GEngine->Exec(World, TEXT(
"r.SSR 0"));
994 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
995 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 0"));
996 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 4"));
997 GEngine->Exec(World, TEXT(
"r.OcclusionQueryLocation 1"));
998 GEngine->Exec(World, TEXT(
"foliage.DensityScale 0"));
999 GEngine->Exec(World, TEXT(
"grass.DensityScale 0"));
1000 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0 "));
@ SemanticSegmentationCamera
void SetInstancedRendering(bool ShouldRender)
virtual ESensorTypes GetSensorType() const
void SetMaxSpeed(float MaxSpeed=1500.0f)
bool IsNiagaraComponentVisible()
void SetNiagaraComponentVisibility(bool Visible)
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
void ApplySettings(bool bCheckForCommandLineOverrides) override
EAntiAliasing GetAntiAliasingMethod() const
void OnSensorSpawned(ASensor *SensorPtr)
void SetStartWindowInitiallyMinimized(bool Minimized)
void SetQualityLevelFromString(const FString &QualityLevelString)
EShadowCacheInvalidationBehavior GetShadowCacheInvalidationBehavior() const
void SetUltraWithRaytracingLevel()
void SetSpectatorMaxSpeed(float MaxSpeed)
bool GetIsUsingVirtualShadowMaps() const
int32 GetWorldPositionOffsetRenderDistance() const
void SetShowSpectatorRainAndSnowfall(bool Show)
bool GetStartWindowInitiallyMinimized() const
bool ParseLaunchArguments()
FDelegateHandle AdvanceFramesHandle
FDelegateHandle EndOfFrameHandle
void SetSimulationSettings(FGlobalSimulationSettings NewSettings)
void AdvanceTime(float TimeToAdvance)
void ChangeMapByName(FString MapName)
int NumberOfPostProcessingSensors
void AdvanceFrameCount(int32 FramesToAdvance)
FGraphicsSettingsDelegate OnGraphicsSettingsChanged
void SetAntiAliasingMethod(EAntiAliasing AntiAliasingMethod)
int GetGlobalTargetFrameRate() const
const TArray< FString > MapPaths
void SetInstancedRenderingVisibility(bool Visible)
void SetLowQualityLevel()
virtual void PostInitProperties() override
float GetGlobalTimeDilation() const
void SetShadowCSMCache(bool CacheShadowCSM)
void SetAntiAliasingMethodFromString(const FString &AntiAliasingMethodString)
FGlobalSimulationSettings SimulationSettings
void SetUseVirtualShadowMaps(bool UseVirtualShadowMaps)
void SetGraphicsSettings(FGlobalGraphicsSettings NewSettings)
void SetBalancedQualityLevel()
TWeakObjectPtr< UWorld > CurrentWorld
void LoadSettings(bool bForceReload=false) override
void SetQualityLevel(EQualityLevel newQualityLevel)
void Setup(UWorld *World)
int32 GetNumberOfWorkerThreads() const
float GetNaniteMaxPixelsPerEdge() const
void SetGlobalTimeDilation(float TimeDilation)
static FString CurrentMapName
void SetWindowMode(EWindowMode::Type WindowType)
void SetGlobalTargetFrameRate(int NewTargetFrameRate)
void SetRenderCustomDepthPass(bool RenderCustomDepthPass)
bool GetIsRenderingCustomDepthPass() const
void OnSensorDestroyed(ASensor *SensorPtr)
void SetGrassVisibility(bool Visible)
void SetUltraQualityLevel()
bool GetShadowCSMCache() const
void SetShadowCacheInvalidationBehaviorFromString(const FString &BehaviourString)
void SetShadowCacheInvalidationBehavior(EShadowCacheInvalidationBehavior Behaviour=EShadowCacheInvalidationBehavior::Rigid)
void ChangeMapByMapPath(const FString &Path)
FString GetConsoleVariableValueString(const FString &VariableName) const
void PauseSimulationEndOfThisFrame()
static UAgrarsenseSettings * GetAgrarsenseSettings()
bool GetGrassVisibility() const
void SetWorldPositionOffsetRenderDistance(int32 WorldPositionOffsetDistance)
FGlobalGraphicsSettings GraphicsSettings
const TArray< FString > MapNames
void SetWorldRendering(bool enabled)
void SetNaniteMaxPixelsPerEdge(float MaxPixelsPerEdge=1.0f)
bool IsRaytracingSupported() const
static ASpectator * GetSpectator(const UObject *WorldContextObject)
static AInstancedRenderer * GetInstancedRenderer(const UObject *WorldContextObject)
static FString ConvertQualityLevelToString(EQualityLevel QualityLevel)
static EQualityLevel ConvertStringToQualityLevel(const FString &String)
static EAntiAliasing ConvertStringToAntiAliasingMethod(const FString &String)
static USensorManager * Get()
FSensorDestroyedDelegate OnSensorDestroyed
FSensorSpawnedDelegate OnSensorSpawned
EQualityLevel QualityLevel
bool DisableSpectatorRendering
float NaniteMaxPixelsPerEdge
EAntiAliasing AntiAliasingMethod
int32 WorldPositionOffsetDistance
EShadowCacheInvalidationBehavior FoliageShadowCacheInvalidationBehaviour
bool UseVirtualShadowMaps
bool ShowSpectatorRainAndSnowfall
bool StartCameraWindowsMinimized