Fix for StreetLights not registering in UCarlaLightSubsystem.

This commit is contained in:
Axel 2021-07-20 09:47:32 +02:00 committed by bernat
parent 5a41195afc
commit c7ce0eab7a
3 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "Carla.h"
#include "Carla/Game/CarlaGameModeBase.h"
#include "Carla/Game/CarlaHUD.h"
#include "Carla/Lights/CarlaLight.h"
#include "Engine/DecalActor.h"
#include "Engine/LevelStreaming.h"
#include "Engine/LocalPlayer.h"
@ -196,6 +197,19 @@ void ACarlaGameModeBase::BeginPlay()
if (LMManager) {
LMManager->RegisterInitialObjects();
}
// Manually run begin play on lights as it may not run on sublevels
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), FoundActors);
for(AActor* Actor : FoundActors)
{
TArray<UCarlaLight*> Lights;
Actor->GetComponents(Lights, false);
for(UCarlaLight* Light : Lights)
{
Light->BeginPlay();
}
}
}
void ACarlaGameModeBase::Tick(float DeltaSeconds)

View File

@ -15,6 +15,11 @@ UCarlaLight::UCarlaLight()
void UCarlaLight::BeginPlay()
{
if(bRegistered)
{
return;
}
Super::BeginPlay();
UWorld *World = GetWorld();
@ -23,6 +28,7 @@ void UCarlaLight::BeginPlay()
UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
CarlaLightSubsystem->RegisterLight(this);
}
bRegistered = true;
}
void UCarlaLight::OnComponentDestroyed(bool bDestroyingHierarchy)

View File

@ -104,4 +104,6 @@ protected:
private:
void RecordLightChange() const;
bool bRegistered = false;
};