Fixed UCarlaLight related crash

This commit is contained in:
Axel 2021-09-08 13:01:55 +02:00 committed by bernat
parent 717295e553
commit 808d00d0b0
3 changed files with 12 additions and 3 deletions

View File

@ -222,7 +222,7 @@ void ACarlaGameModeBase::BeginPlay()
Actor->GetComponents(Lights, false); Actor->GetComponents(Lights, false);
for(UCarlaLight* Light : Lights) for(UCarlaLight* Light : Lights)
{ {
Light->BeginPlay(); Light->RegisterLight();
} }
} }
EnableOverlapEvents(); EnableOverlapEvents();

View File

@ -14,20 +14,26 @@ UCarlaLight::UCarlaLight()
} }
void UCarlaLight::BeginPlay() void UCarlaLight::BeginPlay()
{
Super::BeginPlay();
RegisterLight();
}
void UCarlaLight::RegisterLight()
{ {
if(bRegistered) if(bRegistered)
{ {
return; return;
} }
Super::BeginPlay();
UWorld *World = GetWorld(); UWorld *World = GetWorld();
if(World) if(World)
{ {
UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>(); UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
CarlaLightSubsystem->RegisterLight(this); CarlaLightSubsystem->RegisterLight(this);
} }
bRegistered = true; bRegistered = true;
} }

View File

@ -45,6 +45,9 @@ public:
void OnComponentDestroyed(bool bDestroyingHierarchy) override; void OnComponentDestroyed(bool bDestroyingHierarchy) override;
UFUNCTION(BlueprintCallable, Category = "Carla Light")
void RegisterLight();
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Carla Light") UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Carla Light")
void UpdateLights(); void UpdateLights();