CARLA
Loading...
Searching...
No Matches
CarlaLight.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "CarlaLight.h"
11
12#include <util/ue-header-guard-begin.h>
13#include "Components/LocalLightComponent.h"
14#include "Components/StaticMeshComponent.h"
15#include "HAL/IConsoleManager.h"
16#include "Materials/MaterialInstanceDynamic.h"
17#include <util/ue-header-guard-end.h>
18
19// The CARLA light content (street lamps, building lights...) was authored for
20// UE4: a street lamp's CarlaLight ships intensity ~20, and the lamp blueprints
21// feed that same number both to the light component's SetIntensity AND to the
22// mesh material's EmissiveIntensity parameter (the glowing bulb). Under
23// UE 5.8's inverse-square photometric units, 20 lumens emits next to nothing
24// and night scenes render black. Scaling CarlaLight::LightIntensity itself (a
25// previous fix, x10000) cannot work: the blueprint pushes that one value to
26// both sinks, so any factor that makes the light visible also drives the
27// material emissive to hundreds of thousands and turns every pole into a
28// white-hot rod that drags the auto-exposure down and blinds the scene.
29// Instead, keep LightIntensity at its authored value (the emissive path and
30// the client-facing light API stay UE4-compatible) and scale the LIGHT
31// COMPONENT's intensity right after every code path that lets the blueprint
32// push authored values into it (see ApplyLegacyComponentConversion).
33// Same story for attenuation radius: UE4-era lamp content ships spot/point
34// lights with ~10-16 m attenuation, so even a bright lamp lights almost
35// nothing under UE5 -- the pool dies a few meters past each pole. Enforce a
36// minimum radius on every light component of a registered CarlaLight;
37// 7000 cm (70 m) lets 30 m-spaced street lamp pools overlap with inverse-
38// square falloff doing the actual attenuation well before the cutoff.
39static TAutoConsoleVariable<float> CVarCarlaLightMinAttenuationRadius(
40 TEXT("carla.Light.MinAttenuationRadius"),
41 7000.0f,
42 TEXT("Minimum attenuation radius (cm) enforced on the light components of every ")
43 TEXT("registered CarlaLight. Set 0 to leave authored radii untouched."),
44 ECVF_Default);
45
46// Street lights are photometric: their components run in lumens and the
47// CarlaLight intensity (Light Defaults, client API) IS lumens -- an LED road
48// luminaire is 10-25 klm, giving 0.5-2 cd/m2 on the asphalt like real street
49// lighting. The modern lamp blueprints author UE4-era values of 12-20, i.e.
50// kilolumens, so authored values below CarlaLightMaxAuthoredIntensity are
51// multiplied by this scale. The old calibration (x500000, from when the
52// project had no auto exposure) gave 1 million lumens per lamp head.
53// Building/other/vehicle lights keep the older, milder calibration.
54static TAutoConsoleVariable<float> CVarCarlaLightStreetIntensityScale(
55 TEXT("carla.Light.StreetIntensityScale"),
56 1000.0f,
57 TEXT("Multiplier from authored UE4-era STREET light intensities (below 1000, i.e. kilolumens) ")
58 TEXT("to lumens, applied to the owner's light components after every blueprint intensity ")
59 TEXT("push. Values of 1000 and above are taken as lumens already."),
60 ECVF_Default);
61
62// The re-authored legacy street lamps (00_LegacyAssets) carry 6-10 MILLION,
63// calibrated against the old x500000 scale: bring them back to lumens.
64static constexpr float CarlaLightLegacyStreetThreshold = 1000000.0f;
65static constexpr float CarlaLightLegacyStreetDivisor = 500.0f;
66
67static TAutoConsoleVariable<float> CVarCarlaLightLegacyIntensityScale(
68 TEXT("carla.Light.LegacyIntensityScale"),
69 10000.0f,
70 TEXT("Multiplier converting small UE4-era CarlaLight intensities of non-street lights ")
71 TEXT("(building, vehicle, other) to UE5 photometric units, applied to the owner's light ")
72 TEXT("components after every blueprint intensity push. Set 1 to leave component ")
73 TEXT("intensities untouched."),
74 ECVF_Default);
75
76// Blueprint pushes write ABSOLUTE authored values (tens to hundreds) into the
77// component; the conversion then multiplies the component intensity by the
78// scale above (giving hundreds of thousands to millions). Values already at
79// converted magnitude must not be scaled again when the conversion re-runs
80// after a state change whose blueprint handler did not push a fresh
81// intensity. Authored UE4 content tops out around a few hundred, so anything
82// at or above this threshold is treated as already converted.
83static constexpr float CarlaLightMaxAuthoredIntensity = 1000.0f;
84
85UCarlaLight::UCarlaLight()
86{
87 PrimaryComponentTick.bCanEverTick = false;
88}
89
90void UCarlaLight::OnRegister()
91{
92 Super::OnRegister();
93 // Same rationale as BeginPlay below: a copy-pasted/duplicated actor's
94 // component inherits the source's already-Registered flag verbatim, which
95 // silently skipped subsystem registration for every editor-placed
96 // duplicate (confirmed with bus stops/billboards -- 11 and 4 placed
97 // instances respectively, only the original ever showed up in a scan,
98 // since RegisterLight() below no-ops when this flag is already set).
99 flags &= ~ECarlaLightFlags::Registered;
100 RegisterLight();
101}
102
103void UCarlaLight::BeginPlay()
104{
105 Super::BeginPlay();
106
107 // A fresh BeginPlay means this instance is not registered with this
108 // world's subsystem, whatever a copied flag claims: template-based
109 // spawning (PCG Spawn Actor and friends) copies the template component's
110 // flags wholesale, which used to make every cloned street light skip
111 // registration (1 of 133 PCG-spawned lamps registered), and EndPlay never
112 // cleared the flag either.
113 flags &= ~ECarlaLightFlags::Registered;
114 RegisterLight();
115}
116
117void UCarlaLight::RegisterLight()
118{
120 {
121 return;
122 }
123
124 if (GetOwner() != nullptr)
125 {
126 ActivateAndConfigureLightComponents(GetOwner());
127 }
128
129 ApplyLegacyComponentConversion();
130 ApplyLightAssetDefault();
131
132 UWorld *World = GetWorld();
133 if (World != nullptr)
134 {
135 // OnRegister now runs for every world, including inactive worlds
136 // (e.g. double-clicking a map asset in the Content Browser opens an
137 // EWorldType::Inactive preview world). UCarlaLightSubsystem doesn't
138 // support that world type, so GetSubsystem returns nullptr there.
139 if (UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>())
140 {
141 CarlaLightSubsystem->RegisterLight(this);
142 }
143 }
145}
146
147void UCarlaLight::OnUnregister()
148{
149 UWorld* World = GetWorld();
150 if (World != nullptr)
151 {
152 if (UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>())
153 {
154 CarlaLightSubsystem->UnregisterLight(this);
155 }
156 }
157 flags &= ~ECarlaLightFlags::Registered;
158 Super::OnUnregister();
159}
160
161void UCarlaLight::OnComponentDestroyed(bool bDestroyingHierarchy)
162{
163 // OnRegister above now registers in the editor too, not just BeginPlay --
164 // so a component actually destroyed (level edit, not just a construction-
165 // script re-register, which doesn't hit this at all) needs to unregister
166 // here too, or deleting a light in the editor leaves a dangling pointer in
167 // the subsystem until the next EndPlay/Deinitialize. Safe to call
168 // alongside EndPlay's own unregister: both go through UnregisterLight,
169 // which no-ops if already absent.
170 UWorld* World = GetWorld();
171 if (World != nullptr)
172 {
173 if (UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>())
174 CarlaLightSubsystem->UnregisterLight(this);
175 }
176 flags &= ~ECarlaLightFlags::Registered;
177
178 Super::OnComponentDestroyed(bDestroyingHierarchy);
179}
180
181void UCarlaLight::EndPlay(const EEndPlayReason::Type EndPlayReason)
182{
183 UWorld *World = GetWorld();
184 if(World)
185 {
186 UCarlaLightSubsystem* CarlaLightSubsystem = World->GetSubsystem<UCarlaLightSubsystem>();
187 CarlaLightSubsystem->UnregisterLight(this);
188 }
189 // Allow re-registration if this component gets a new BeginPlay (level
190 // streaming, actor reuse); the flag used to stay set forever.
191 flags &= ~ECarlaLightFlags::Registered;
192 Super::EndPlay(EndPlayReason);
193}
194
195void UCarlaLight::ApplyLegacyComponentConversion()
196{
197 if (GetOwner() == nullptr)
198 {
199 return;
200 }
201 ScaleLightComponentIntensities(GetOwner(), LightType, &ConvertedIntensities);
202}
203
204void UCarlaLight::ActivateAndConfigureLightComponents(AActor* Owner)
205{
206 // ULocalLightComponent, not UPointLightComponent: URectLightComponent is a
207 // sibling of UPointLightComponent (both derive from ULocalLightComponent),
208 // not a subclass -- every GetComponents<UPointLightComponent> call in this
209 // file used to silently find nothing on any RectLight-based prop (bus
210 // stops, billboards), making their Intensity/Color controls complete
211 // no-ops on the actual light despite the panel looking like it worked.
212 // Widen undersized authored attenuation radii so the light actually
213 // reaches the road (see cvar comment above).
214 const float MinRadius = CVarCarlaLightMinAttenuationRadius.GetValueOnGameThread();
215 if (MinRadius <= 0.0f || Owner == nullptr)
216 {
217 return;
218 }
219 TArray<ULocalLightComponent*> LightComponents;
220 Owner->GetComponents<ULocalLightComponent>(LightComponents);
221 for (ULocalLightComponent* LightComponent : LightComponents)
222 {
223 if (LightComponent->AttenuationRadius < MinRadius)
224 {
225 LightComponent->SetAttenuationRadius(MinRadius);
226 }
227 // Lamp blueprints commonly embed the light inside the opaque lamp-head
228 // mesh; with shadow casting on, the head fully occludes its own light
229 // and the lamp illuminates nothing. Street furniture doesn't need
230 // per-lamp shadows.
231 LightComponent->SetCastShadows(false);
232 // Some lamp content ships decorative IES gobos (e.g. XArrowDiffuse on
233 // BP_StreetLight01) that mask virtually all of the light's output; a
234 // street light needs its raw cone. Drop the profile.
235 LightComponent->SetIESTexture(nullptr);
236 // Registered lights are driven at runtime (day/night, client API);
237 // Stationary components with no built lighting contribute nothing in
238 // -game. Make them movable so they always render dynamically.
239 LightComponent->SetMobility(EComponentMobility::Movable);
240 // UE4-era lamp content ships light components with bAutoActivate off
241 // (UE4 rendered lights regardless of active state, so nobody noticed);
242 // UE5 culls inactive light components outright, which blacked out
243 // every lamp no matter the intensity. Activate them -- on/off is
244 // driven through intensity/visibility by the blueprints, not through
245 // component activation.
246 if (!LightComponent->IsActive())
247 {
248 LightComponent->SetActive(true);
249 }
250 }
251}
252
253float UCarlaLight::GetLegacyIntensityScale(ELightType LightType)
254{
255 return (LightType == ELightType::Street)
256 ? CVarCarlaLightStreetIntensityScale.GetValueOnGameThread()
257 : CVarCarlaLightLegacyIntensityScale.GetValueOnGameThread();
258}
259
260float UCarlaLight::StreetIntensityToLumens(float Intensity)
261{
262 if (Intensity > 0.0f && Intensity < CarlaLightMaxAuthoredIntensity)
263 return Intensity * CVarCarlaLightStreetIntensityScale.GetValueOnGameThread();
264 if (Intensity >= CarlaLightLegacyStreetThreshold)
265 return Intensity / CarlaLightLegacyStreetDivisor;
266 return Intensity;
267}
268
269void UCarlaLight::ScaleLightComponentIntensities(AActor* Owner, ELightType LightType,
270 TMap<FObjectKey, float>* Converted)
271{
272 if (Owner == nullptr)
273 {
274 return;
275 }
276 TArray<ULocalLightComponent*> LightComponents;
277 Owner->GetComponents<ULocalLightComponent>(LightComponents);
278 const float Scale = GetLegacyIntensityScale(LightType);
279 for (ULocalLightComponent* LightComponent : LightComponents)
280 {
281 const float Current = LightComponent->Intensity;
282 // Still the value written last time: no blueprint push since, nothing to convert.
283 if (Converted != nullptr)
284 {
285 const float* Written = Converted->Find(LightComponent);
286 if (Written != nullptr && *Written == Current)
287 continue;
288 }
289 float Result = Current;
290 if (LightType == ELightType::Street)
291 {
292 // Authored content mixes Unitless and Lumens; the value is lumens.
293 if (LightComponent->IntensityUnits != ELightUnits::Lumens)
294 LightComponent->SetIntensityUnits(ELightUnits::Lumens);
295 Result = StreetIntensityToLumens(Current);
296 }
297 else if (Scale != 1.0f && Current > 0.0f && Current < CarlaLightMaxAuthoredIntensity)
298 {
299 UE_LOG(LogCarla, VeryVerbose, TEXT("CarlaLight conversion: owner %s component %s intensity %f visible %d"),
300 *Owner->GetName(), *LightComponent->GetName(), Current, LightComponent->IsVisible() ? 1 : 0);
301 Result = Current * Scale;
302 }
303 if (Result != Current)
304 LightComponent->SetIntensity(Result);
305 if (Converted != nullptr)
306 Converted->Add(LightComponent, Result);
307 }
308}
309
310void UCarlaLight::ApplyIntensityToComponents(float Intensity)
311{
312 // Drives the light components directly instead of going through the
313 // BlueprintImplementableEvent UpdateLights -> ChangeLight dispatcher ->
314 // SetLight chain: confirmed by instrumented testing that that chain never
315 // actually reaches the native component (PRE/POST-UpdateLights logged
316 // identical component intensity regardless of the requested value, both at
317 // registration and on a live Reapply). Several ported lamp blueprints have
318 // dead UpdateLights graphs (see ApplyLightOnToComponents); intensity had no
319 // native workaround the way on/off does, until now.
320 AActor* Owner = GetOwner();
321 if (Owner == nullptr)
322 {
323 return;
324 }
325 TArray<ULocalLightComponent*> LightComponents;
326 Owner->GetComponents<ULocalLightComponent>(LightComponents);
327 // Already in final units: recorded so the legacy conversion leaves it alone.
328 if (LightType == ELightType::Street)
329 {
330 const float Lumens = StreetIntensityToLumens(Intensity);
331 for (ULocalLightComponent* LightComponent : LightComponents)
332 {
333 if (LightComponent->IntensityUnits != ELightUnits::Lumens)
334 LightComponent->SetIntensityUnits(ELightUnits::Lumens);
335 LightComponent->SetIntensity(Lumens);
336 ConvertedIntensities.Add(LightComponent, Lumens);
337 }
338 return;
339 }
340 const float Scale = GetLegacyIntensityScale(LightType);
341 for (ULocalLightComponent* LightComponent : LightComponents)
342 {
343 LightComponent->SetIntensity(Intensity * Scale);
344 ConvertedIntensities.Add(LightComponent, Intensity * Scale);
345 }
346}
347
348void UCarlaLight::ApplyColorToComponents(FLinearColor Color)
349{
350 AActor* Owner = GetOwner();
351 if (Owner == nullptr)
352 {
353 return;
354 }
355 TArray<ULocalLightComponent*> LightComponents;
356 Owner->GetComponents<ULocalLightComponent>(LightComponents);
357 for (ULocalLightComponent* LightComponent : LightComponents)
358 {
359 LightComponent->SetLightColor(Color);
360 }
361}
362
363void UCarlaLight::SetLightIntensity(float Intensity)
364{
365 LightIntensity = Intensity;
366 ApplyIntensityToComponents(Intensity);
367 // Not recorded on its own (SetLightState is), but Multi-GPU secondaries
368 // mirror every change.
369 if (auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld()))
370 {
371 Episode->MarkSceneLightChanged(GetId());
372 }
373}
374
375float UCarlaLight::GetLightIntensity() const
376{
377 return LightIntensity;
378}
379
380void UCarlaLight::SetLightColor(FLinearColor Color)
381{
382 LightColor = Color;
383 ApplyColorToComponents(Color);
384 RecordLightChange();
385}
386
387FLinearColor UCarlaLight::GetLightColor() const
388{
389 return LightColor;
390}
391
392void UCarlaLight::SetLightOn(bool bOn)
393{
394 flags = bOn ? (flags | ECarlaLightFlags::TurnedOn) : (flags & ~ECarlaLightFlags::TurnedOn);
395 UpdateLights();
396 ApplyLightOnToComponents(bOn);
397 ApplyLegacyComponentConversion();
398 RecordLightChange();
399}
400
401void UCarlaLight::HandleDayTimeChanged(bool bIsDay)
402{
403 DayTimeChanged(bIsDay);
404 // Street already auto-toggled; Building and Vehicle (parked-car decoration,
405 // not the ego vehicle's driver-controlled lights) should too -- "Other" is
406 // left alone, its members are too varied to assume night-on is always right
407 // for the real light component. The emissive bulb/glow material follows
408 // the exact same gate: a lit bulb visible in broad daylight looks wrong for
409 // street lamps specifically (confirmed -- night was fine, day never turned
410 // it back off once this was scoped down to a night-only restore). Forcing
411 // it to 0 for EVERY LightType including "Other" was tried first and
412 // reverted: that broke the tool's live-editing/testing use during daytime
413 // (ClearNoon, the default and most common state) for lights that don't
414 // want automatic day/night emissive behavior at all.
415 if (LightType == ELightType::Street
416 || LightType == ELightType::Building
417 || LightType == ELightType::Vehicle)
418 {
419 SetLightOn(!bIsDay);
420 // ApplyEmissiveVisualState rather than SetEmissiveIntensity so the
421 // authored/saved EmissiveIntensity member isn't clobbered by the
422 // day-time 0 -- the next edit (or the next night) still has the real
423 // value to restore. Re-pushed (not just toggled) on the night side
424 // because the ported lamp blueprints' own DayTimeChanged graphs don't
425 // reliably restore it themselves (see ApplyEmissiveToComponents),
426 // leaving it stuck off after a day->night round trip otherwise.
427 ApplyEmissiveVisualState(bIsDay ? 0.0f : EmissiveIntensity);
428 }
429}
430
431void UCarlaLight::ApplyLightAssetDefault()
432{
433 AActor* Owner = GetOwner();
434 if (Owner == nullptr)
435 {
436 return;
437 }
438
439 // GetLightClassKey resolves the owning actor's class (BP_StreetLight01_C,
440 // ...), or a shared building-material family for buildings like
441 // BP_Apt20_A_C..F_C -- not this component's own class: every light-bearing
442 // actor places the same BP_Lights component, so GetClass() here would
443 // always read "BP_Lights_C" and collapse every light in the level into one
444 // bucket.
445 bool bIsBuildingClass = false;
447 if (!ULightDefaultsJsonUtils::GetLightDefault(ULightDefaultsJsonUtils::GetLightClassKey(Owner, bIsBuildingClass), LightType, Default))
448 {
449 return;
450 }
451 SetLightColor(Default.Color);
452 SetLightIntensity(Default.Intensity);
453 SetEmissiveIntensity(Default.EmissiveIntensity);
454}
455
456void UCarlaLight::SetEmissiveIntensity(float Value)
457{
458 EmissiveIntensity = Value;
459 ApplyEmissiveVisualState(Value);
460}
461
462void UCarlaLight::ApplyEmissiveVisualState(float Value)
463{
464 // Apply immediately -- correct for every already-settled actor (which is
465 // most callers: the Light Defaults panel's live edits, Reapply To Level,
466 // day/night toggling). Also apply once more a tick later: called from
467 // RegisterLight (OnRegister), a MID created that early is orphaned --
468 // confirmed by logging the MID's own name, which differs between a
469 // registration-time apply (named after the static parent material, e.g.
470 // "M_StreetLight06_0") and a later apply once the level has finished
471 // settling (named "MaterialInstanceDynamic_N" as expected) -- two
472 // different objects, not the same one reused. Whatever resets the
473 // material slot back to its authored asset happens after OnRegister but
474 // before the component's real render proxy is built, so the same-frame
475 // MID never shows -- confirmed recurring on some content (food trucks)
476 // whose meshes finish setting up later still than a single deferred tick
477 // covers, needing a manual re-edit to actually show. Both applies are
478 // idempotent (same scalar values), so doing both is harmless.
479 ApplyEmissiveToComponents(Value);
480 if (UWorld* World = GetWorld())
481 {
482 // Cancel any still-pending retry from an earlier call first -- see
483 // DeferredEmissiveTimerHandle's comment. Without this, a burst of calls
484 // could leave several independent one-shot timers in flight, each
485 // capturing its own now-stale Value, any of which firing after this
486 // call's immediate apply above would silently undo it.
487 World->GetTimerManager().ClearTimer(DeferredEmissiveTimerHandle);
488 TWeakObjectPtr<UCarlaLight> WeakThis(this);
489 DeferredEmissiveTimerHandle = World->GetTimerManager().SetTimerForNextTick([WeakThis, Value]()
490 {
491 if (WeakThis.IsValid())
492 {
493 WeakThis->ApplyEmissiveToComponents(Value);
494 }
495 });
496 }
497}
498
499float UCarlaLight::GetEmissiveIntensity() const
500{
501 return EmissiveIntensity;
502}
503
504void UCarlaLight::ApplyEmissiveToComponents(float Value)
505{
506 AActor* Owner = GetOwner();
507 if (Owner == nullptr)
508 {
509 return;
510 }
511 // The lamp materials gate their whole emissive Lerp on "On/Off" (authored
512 // defaulting to 0 -- confirmed via M_StreetLight06/M_Artificial_Lamp), so
513 // EmissiveIntensity alone never did anything; flip the gate here too.
514 const float OnOff = (Value > 0.0f) ? 1.0f : 0.0f;
515 TArray<UStaticMeshComponent*> MeshComponents;
516 Owner->GetComponents<UStaticMeshComponent>(MeshComponents);
517 for (UStaticMeshComponent* MeshComponent : MeshComponents)
518 {
519 const int32 NumMaterials = MeshComponent->GetNumMaterials();
520 for (int32 MaterialIndex = 0; MaterialIndex < NumMaterials; ++MaterialIndex)
521 {
522 if (UMaterialInstanceDynamic* MID = MeshComponent->CreateAndSetMaterialInstanceDynamic(MaterialIndex))
523 {
524 MID->SetScalarParameterValue(TEXT("EmissiveIntensity"), Value);
525 MID->SetScalarParameterValue(TEXT("On/Off"), OnOff);
526 }
527 }
528 }
529}
530
531void UCarlaLight::ApplyLightOnToComponents(bool bOn)
532{
533 AActor* Owner = GetOwner();
534 if (Owner == nullptr)
535 {
536 return;
537 }
538 TArray<ULocalLightComponent*> LightComponents;
539 Owner->GetComponents<ULocalLightComponent>(LightComponents);
540 for (ULocalLightComponent* LightComponent : LightComponents)
541 {
542 LightComponent->SetVisibility(bOn);
543 }
544}
545
546bool UCarlaLight::GetLightOn() const
547{
548 return (flags & ECarlaLightFlags::TurnedOn) != ECarlaLightFlags();
549}
550
551void UCarlaLight::SetLightType(ELightType Type)
552{
553 LightType = Type;
554}
555
556ELightType UCarlaLight::GetLightType() const
557{
558 return LightType;
559}
560
561carla::rpc::LightState UCarlaLight::GetLightState()
562{
564 GetLocation(),
565 LightIntensity,
566 static_cast<carla::rpc::LightState::LightGroup>(LightType),
567 LightColor,
568 GetLightOn()
569 );
570
571 state._id = GetId();
572
573 return state;
574}
575
576void UCarlaLight::SetLightState(carla::rpc::LightState LightState)
577{
578 SetLightState(
579 LightState._intensity,
580 LightState._color,
581 static_cast<ELightType>(LightState._group),
582 LightState._active);
583}
584
585void UCarlaLight::SetLightState(float Intensity, FLinearColor Color, ELightType Type, bool bOn)
586{
587 LightIntensity = Intensity;
588 LightColor = Color;
589 LightType = Type;
590 flags = bOn ? (flags | ECarlaLightFlags::TurnedOn) : (flags & ~ECarlaLightFlags::TurnedOn);
591 UpdateLights();
592 ApplyLightOnToComponents(bOn);
593 ApplyLegacyComponentConversion();
594 RecordLightChange();
595}
596
597FVector UCarlaLight::GetLocation() const
598{
599 // Reached from the RPC thread (get_lights); during a map transition or a
600 // World Partition stream-out the owner and the game mode can be gone
601 // while this component is still registered.
602 const AActor* Owner = GetOwner();
603 auto Location = Owner ? Owner->GetActorLocation() : FVector::ZeroVector;
604 ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(GetWorld());
605 ALargeMapManager* LargeMap = GameMode ? GameMode->GetLMManager() : nullptr;
606 if (LargeMap)
607 {
609 }
610 return Location;
611}
612
613int UCarlaLight::GetId() const
614{
615 return Id;
616}
617
618void UCarlaLight::SetId(int InId)
619{
620 Id = InId;
621}
622
623void UCarlaLight::RecordLightChange() const
624{
625 auto* Episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
626 if (Episode)
627 {
628 auto* Recorder = Episode->GetRecorder();
629 if (Recorder && Recorder->IsEnabled())
630 {
631 Recorder->AddEventLightSceneChanged(this);
632 }
633 Episode->MarkSceneLightChanged(GetId());
634 }
635}
static TAutoConsoleVariable< float > CVarCarlaLightMinAttenuationRadius(TEXT("carla.Light.MinAttenuationRadius"), 7000.0f, TEXT("registered CarlaLight. Set 0 to leave authored radii untouched."), ECVF_Default)
static constexpr float CarlaLightLegacyStreetThreshold
static constexpr float CarlaLightLegacyStreetDivisor
static constexpr float CarlaLightMaxAuthoredIntensity
static TAutoConsoleVariable< float > CVarCarlaLightLegacyIntensityScale(TEXT("carla.Light.LegacyIntensityScale"), 10000.0f, TEXT("intensities untouched."), ECVF_Default)
static TAutoConsoleVariable< float > CVarCarlaLightStreetIntensityScale(TEXT("carla.Light.StreetIntensityScale"), 1000.0f, TEXT("push. Values of 1000 and above are taken as lumens already."), ECVF_Default)
ELightType
Definition CarlaLight.h:30
ECarlaLightFlags
Definition CarlaLight.h:44
Base class for the CARLA Game Mode.
ALargeMapManager * GetLMManager() const
FVector LocalToGlobalLocation(const FVector &InLocation) const
void UnregisterLight(UCarlaLight *CarlaLight)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static FString GetLightClassKey(AActor *Owner, bool &bOutIsBuildingClass)
static bool GetLightDefault(const FString &ClassName, ELightType Group, UPARAM(ref) FLightAssetDefault &OutDefault)