diff --git a/Source/Carla/DynamicWeather.cpp b/Source/Carla/DynamicWeather.cpp index e98699d0d..1bbdf98cf 100644 --- a/Source/Carla/DynamicWeather.cpp +++ b/Source/Carla/DynamicWeather.cpp @@ -68,6 +68,22 @@ ADynamicWeather::ADynamicWeather(const FObjectInitializer& ObjectInitializer) #endif // WITH_EDITORONLY_DATA } +void ADynamicWeather::OnConstruction(const FTransform &Transform) +{ + Super::OnConstruction(Transform); +#if WITH_EDITOR + Update(); +#endif // WITH_EDITOR +} + +void ADynamicWeather::BeginPlay() +{ + Super::BeginPlay(); +#if WITH_EDITOR + Update(); +#endif // WITH_EDITOR +} + #if WITH_EDITOR void ADynamicWeather::PostEditChangeProperty(FPropertyChangedEvent &Event) @@ -121,16 +137,6 @@ FVector ADynamicWeather::GetSunDirection() const return - SphericalCoords.SphericalToUnitCartesian(); } -void ADynamicWeather::Update() -{ - // Modify this actor's rotation according to Sun position. - if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) { - UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor")); - } - - RefreshWeather(); -} - void ADynamicWeather::AdjustSunPositionBasedOnActorRotation() { const FVector Direction = - GetActorQuat().GetForwardVector(); @@ -141,6 +147,18 @@ void ADynamicWeather::AdjustSunPositionBasedOnActorRotation() #if WITH_EDITOR +void ADynamicWeather::Update() +{ + // Modify this actor's rotation according to Sun position. + if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) { + UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor")); + } + + if (bRefreshAutomatically) { + RefreshWeather(); + } +} + bool ADynamicWeather::LoadFromConfigFile() { FString FileName; diff --git a/Source/Carla/DynamicWeather.h b/Source/Carla/DynamicWeather.h index bd6441628..e4b57f797 100644 --- a/Source/Carla/DynamicWeather.h +++ b/Source/Carla/DynamicWeather.h @@ -20,6 +20,10 @@ public: ADynamicWeather(const FObjectInitializer& ObjectInitializer); + virtual void OnConstruction(const FTransform &Transform) override; + + virtual void BeginPlay() override; + #if WITH_EDITOR virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; @@ -47,12 +51,12 @@ public: private: - void Update(); - void AdjustSunPositionBasedOnActorRotation(); #if WITH_EDITOR + void Update(); + bool LoadFromConfigFile(); bool SaveToConfigFile() const; @@ -64,9 +68,17 @@ private: UPROPERTY() UArrowComponent *ArrowComponent; + /** If true, the weather is refreshed on construction and at begin play. + * Useful for editing the weather (Editor only). + */ + UPROPERTY(Category = "Weather Description", EditAnywhere) + bool bRefreshAutomatically = false; + + /** Load the section with the currently set name. */ UPROPERTY(Category = "Weather Description", EditAnywhere) bool bLoadFromConfigFile = false; + /** Save current settings to disk. */ UPROPERTY(Category = "Weather Description", EditAnywhere) bool bSaveToConfigFile = false;