From 808d00d0b0cf253e2f6190f6aa96f85b6ec06b52 Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 8 Sep 2021 13:01:55 +0200 Subject: [PATCH] Fixed UCarlaLight related crash --- .../Carla/Source/Carla/Game/CarlaGameModeBase.cpp | 2 +- .../Plugins/Carla/Source/Carla/Lights/CarlaLight.cpp | 10 ++++++++-- .../Plugins/Carla/Source/Carla/Lights/CarlaLight.h | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp index db005543f..109dc3a3d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.cpp @@ -222,7 +222,7 @@ void ACarlaGameModeBase::BeginPlay() Actor->GetComponents(Lights, false); for(UCarlaLight* Light : Lights) { - Light->BeginPlay(); + Light->RegisterLight(); } } EnableOverlapEvents(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.cpp index b1803caeb..92d343bb5 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.cpp @@ -14,20 +14,26 @@ UCarlaLight::UCarlaLight() } void UCarlaLight::BeginPlay() +{ + Super::BeginPlay(); + + RegisterLight(); +} + +void UCarlaLight::RegisterLight() { if(bRegistered) { return; } - Super::BeginPlay(); - UWorld *World = GetWorld(); if(World) { UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem(); CarlaLightSubsystem->RegisterLight(this); } + bRegistered = true; } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.h index b4774386c..29683d44c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Lights/CarlaLight.h @@ -45,6 +45,9 @@ public: void OnComponentDestroyed(bool bDestroyingHierarchy) override; + UFUNCTION(BlueprintCallable, Category = "Carla Light") + void RegisterLight(); + UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Carla Light") void UpdateLights();