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"));
85 GEngine->Exec(World, TEXT(
"t.IdleWhenNotForeground 0"));
103 if (FParse::Param(FCommandLine::Get(), TEXT(
"Fullscreen")))
107 else if (FParse::Param(FCommandLine::Get(), TEXT(
"WindowedFullscreen")))
120 Super::PostInitProperties();
122#if UE_BUILD_SHIPPING || UE_BUILD_DEVELOPMENT
132 return Cast<UAgrarsenseSettings>(UGameUserSettings::GetGameUserSettings());
137 Super::LoadSettings(bForceReload);
142 Super::ApplySettings(bCheckForCommandLineOverrides);
150 bool SettingsWereChanged =
false;
153 FString AntiAliasingString;
154 if (FParse::Value(FCommandLine::Get(), TEXT(
"-antialiasing="), AntiAliasingString))
157 int32 AntiAliasingInt;
158 if (AntiAliasingString.IsNumeric())
160 AntiAliasingInt = FCString::Atoi(*AntiAliasingString);
163 SettingsWereChanged =
true;
168 if (FParse::Param(FCommandLine::Get(), TEXT(
"-no-spectator-rendering")))
171 SettingsWereChanged =
true;
175 if (FParse::Param(FCommandLine::Get(), TEXT(
"-start-camerawindows-minimized")))
178 SettingsWereChanged =
true;
182 FString QualityLevelString;
183 if (FParse::Value(FCommandLine::Get(), TEXT(
"-quality-level="), QualityLevelString))
186 SettingsWereChanged =
true;
189 return SettingsWereChanged;
194 return FPlatformMisc::NumberOfWorkerThreadsToSpawn();
199 IConsoleVariable* ConsoleVariable = IConsoleManager::Get().FindConsoleVariable(*VariableName);
202 FString VariableValue = ConsoleVariable->GetString();
203 return VariableValue;
227 UGameUserSettings* UserSettings = GEngine->GetGameUserSettings();
230 UserSettings->SetFullscreenMode(WindowType);
231 UserSettings->ApplySettings(
false);
260 if (!GEngine || !World)
269 GEngine->Exec(World, TEXT(
"grass.enable 0"));
270 GEngine->Exec(World, TEXT(
"grass.FlushCache"));
274 GEngine->Exec(World, TEXT(
"grass.enable 1"));
293 if (GEngine && World)
299 GEngine->Exec(World, TEXT(
"r.Shadow.CSMCaching 1"));
303 GEngine->Exec(World, TEXT(
"r.Shadow.CSMCaching 0"));
317 if (InstanceRenderer)
333 if (GEngine && World)
335 MaxPixelsPerEdge = FMath::Clamp(MaxPixelsPerEdge, 0.1f, 10.0f);
337 FString Command = FString::Printf(TEXT(
"r.Nanite.MaxPixelsPerEdge %f"), MaxPixelsPerEdge);
338 GEngine->Exec(World, *Command);
356 FString BehaviourStringToLower = BehaviourString.ToLower();
358 if (BehaviourStringToLower ==
"auto")
362 else if (BehaviourStringToLower ==
"rigid")
366 else if (BehaviourStringToLower ==
"always")
370 else if (BehaviourStringToLower ==
"static")
404 if (GEngine || World)
407 if (RenderCustomDepthPass)
409 GEngine->Exec(World, TEXT(
"r.CustomDepth 3"));
413 GEngine->Exec(World, TEXT(
"r.CustomDepth 0"));
421 if (GEngine || World)
427 GEngine->Exec(World, TEXT(
"r.Shadow.Virtual.Enable 1"));
431 GEngine->Exec(World, TEXT(
"r.Shadow.Virtual.Enable 0"));
458 if (!GEngine || !World)
466 switch (AntiAliasingMethod)
469 ExecCommand = TEXT(
"r.AntiAliasingMethod 0");
473 ExecCommand = TEXT(
"r.AntiAliasingMethod 1");
477 ExecCommand = TEXT(
"r.AntiAliasingMethod 2");
483 ExecCommand = TEXT(
"r.AntiAliasingMethod 4");
490 GEngine->Exec(World, *ExecCommand);
503 if (GEngine && GEngine->GameViewport)
505 GEngine->GameViewport->bDisableWorldRendering = !enabled;
508 FString msg = FString::Printf(TEXT(
"World rendering: %s"), enabled ? TEXT(
"On") : TEXT(
"Off"));
539 FString Msg = FString::Printf(TEXT(
"Graphics settings: %s"), *QualityLevelString);
552 return GetFrameRateLimit();
557 SetFrameRateLimit(NewTargetFrameRate);
570 return UGameplayStatics::GetGlobalTimeDilation(World);
582 UGameplayStatics::SetGlobalTimeDilation(World, TimeDilation);
584 FString msg = FString::Printf(TEXT(
"Global time dilation: %f"), TimeDilation);
597 if (IsValid(Spectator))
614 if (IsValid(Spectator))
626 UGameplayStatics::SetGlobalTimeDilation(World, 0.0f);
627 UGameplayStatics::SetGamePaused(World,
true);
640 UGameplayStatics::SetGamePaused(World,
false);
662 FCoreDelegates::OnEndFrame.Remove(EndOfFrameHandle);
663 EndOfFrameHandle.Reset();
673 if (FramesToAdvance == 0)
728 FTimerHandle AdvanceTimeTimer;
729 World->GetTimerManager().SetTimer(AdvanceTimeTimer, FTimerDelegate::CreateLambda([
this]
736 }), TimeToAdvance,
false);
743 MapName = MapName.ToLower();
745 bool FoundMap =
false;
746 for (int32 i = 0; i <
MapNames.Num(); i++)
751 FString msg = FString::Printf(TEXT(
"Changing map to: %s"), *MapName);
761 FString msg = FString::Printf(TEXT(
"Couldn't find map: %s"), *MapName);
771 UGameplayStatics::OpenLevel(World, *Path, TRAVEL_Absolute);
820 SimulatorLog::Log(
"Graphics settings: Ray tracing not supported on this hardware.");
826 bool RayTracingSupported =
false;
829 IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT(
"r.RayTracing"));
830 if (CVar && CVar->GetInt() > 0 && GRHISupportsRayTracing)
832 RayTracingSupported =
true;
835#if ENGINE_MAJOR_VERSION == 5 && ENGINE_MINOR_VERSION <= 3
839 if (!GDynamicRHI && GDynamicRHI->GetName() == FString(TEXT(
"D3D12")))
841 RayTracingSupported =
false;
847 return RayTracingSupported;
853 if (!World || !GEngine)
858 GEngine->Exec(World, TEXT(
"r.Lumen.HardwareRayTracing 1"));
859 GEngine->Exec(World, TEXT(
"r.RayTracing.Geometry 1"));
860 GEngine->Exec(World, TEXT(
"r.RayTracing.Shadows 1"));
861 GEngine->Exec(World, TEXT(
"r.RayTracing.Reflections 1"));
862 GEngine->Exec(World, TEXT(
"r.RayTracing.AmbientOcclusion 1"));
863 GEngine->Exec(World, TEXT(
"r.RayTracing.GlobalIllumination 1"));
864 GEngine->Exec(World, TEXT(
"r.RayTracing.Translucency 1"));
865 GEngine->Exec(World, TEXT(
"r.RayTracing.SkyLight 1"));
871 if (!World || !GEngine)
876 GEngine->Exec(World, TEXT(
"r.Lumen.HardwareRayTracing 0"));
877 GEngine->Exec(World, TEXT(
"r.RayTracing.Geometry 0"));
878 GEngine->Exec(World, TEXT(
"r.RayTracing.Shadows 0"));
879 GEngine->Exec(World, TEXT(
"r.RayTracing.Reflections 0"));
880 GEngine->Exec(World, TEXT(
"r.RayTracing.AmbientOcclusion 0"));
881 GEngine->Exec(World, TEXT(
"r.RayTracing.GlobalIllumination 0"));
882 GEngine->Exec(World, TEXT(
"r.RayTracing.Translucency 0"));
883 GEngine->Exec(World, TEXT(
"r.RayTracing.SkyLight 0"));
889 if (!World || !GEngine)
897 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 3"));
898 GEngine->Exec(World, TEXT(
"sg.ShadowQuality 3"));
899 GEngine->Exec(World, TEXT(
"sg.TextureQuality 4"));
900 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 4"));
901 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 4"));
903 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.03"));
904 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 1"));
905 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 2"));
906 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 1"));
907 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 64"));
908 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 8"));
909 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 2"));
910 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 1"));
911 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 7"));
912 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
913 GEngine->Exec(World, TEXT(
"r.ShadowQuality 5"));
914 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 1"));
915 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 2"));
916 GEngine->Exec(World, TEXT(
"r.DetailMode 2"));
917 GEngine->Exec(World, TEXT(
"foliage.DensityScale 1"));
918 GEngine->Exec(World, TEXT(
"grass.DensityScale 1"));
919 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0 "));
920 GEngine->Exec(World, TEXT(
"r.Shadow.RadiusThreshold 0.00"));
928 if (!World || !GEngine)
935 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 3"));
936 GEngine->Exec(World, TEXT(
"sg.TextureQuality 3"));
937 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 3"));
938 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 3"));
940 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.03"));
941 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 1"));
942 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 2"));
943 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 1"));
944 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 64"));
945 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 8"));
946 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 2"));
947 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 1"));
948 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 7"));
949 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
950 GEngine->Exec(World, TEXT(
"r.ShadowQuality 3"));
951 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 1"));
952 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 2"));
953 GEngine->Exec(World, TEXT(
"r.DetailMode 2"));
954 GEngine->Exec(World, TEXT(
"r.BloomQuality 4"));
955 GEngine->Exec(World, TEXT(
"foliage.DensityScale 1"));
956 GEngine->Exec(World, TEXT(
"grass.DensityScale 1"));
957 GEngine->Exec(World, TEXT(
"r.Streaming.PoolSize 0 "));
958 GEngine->Exec(World, TEXT(
"r.Shadow.RadiusThreshold 0.01"));
966 if (!World || !GEngine)
973 GEngine->Exec(World, TEXT(
"sg.PostProcessQuality 0"));
974 GEngine->Exec(World, TEXT(
"sg.ShadowQuality 0"));
975 GEngine->Exec(World, TEXT(
"sg.TextureQuality 0"));
976 GEngine->Exec(World, TEXT(
"sg.EffectsQuality 0"));
977 GEngine->Exec(World, TEXT(
"sg.FoliageQuality 0"));
979 GEngine->Exec(World, TEXT(
"r.DefaultFeature.MotionBlur 0"));
980 GEngine->Exec(World, TEXT(
"r.DefaultFeature.Bloom 0"));
981 GEngine->Exec(World, TEXT(
"r.DefaultFeature.AmbientOcclusion 0"));
982 GEngine->Exec(World, TEXT(
"r.DefaultFeature.AmbientOcclusionStaticFraction 0"));
983 GEngine->Exec(World, TEXT(
"r.HZBOcclusion 0"));
984 GEngine->Exec(World, TEXT(
"r.MinScreenRadiusForLights 0.01"));
985 GEngine->Exec(World, TEXT(
"r.SeparateTranslucency 0"));
986 GEngine->Exec(World, TEXT(
"r.FinishCurrentFrame 0"));
987 GEngine->Exec(World, TEXT(
"r.MotionBlurQuality 0"));
988 GEngine->Exec(World, TEXT(
"r.BloomQuality 1"));
989 GEngine->Exec(World, TEXT(
"r.DepthOfFieldQuality 0"));
990 GEngine->Exec(World, TEXT(
"r.TranslucencyVolumeBlur 0"));
991 GEngine->Exec(World, TEXT(
"r.TranslucencyLightingVolumeDim 4"));
992 GEngine->Exec(World, TEXT(
"r.MaxAnisotropy 4"));
993 GEngine->Exec(World, TEXT(
"r.LensFlareQuality 0"));
994 GEngine->Exec(World, TEXT(
"r.SceneColorFringeQuality 0"));
995 GEngine->Exec(World, TEXT(
"r.FastBlurThreshold 0"));
996 GEngine->Exec(World, TEXT(
"r.SSR 0"));
997 GEngine->Exec(World, TEXT(
"r.EarlyZPassMovable 1"));
998 GEngine->Exec(World, TEXT(
"r.TranslucentLightingVolume 0"));
999 GEngine->Exec(World, TEXT(
"r.LightShaftDownSampleFactor 4"));
1000 GEngine->Exec(World, TEXT(
"r.OcclusionQueryLocation 1"));
1001 GEngine->Exec(World, TEXT(
"foliage.DensityScale 0"));
1002 GEngine->Exec(World, TEXT(
"grass.DensityScale 0"));
1003 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