Skip to content

Commit c1ba734

Browse files
authored
Fix for below ground trigger boxes. (#9381)
* Fix for below ground trigger boxes. * Adjusted trigger box for Town15
1 parent 4123578 commit c1ba734

File tree

2 files changed

+86
-14
lines changed

2 files changed

+86
-14
lines changed

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ void ALargeMapManager::PostWorldOriginOffset(UWorld* InWorld, FIntVector InSrcOr
138138

139139
bool ALargeMapManager::AdjustSignHeightToGround(FVector& SpawnLocation, const FString& ActorName, const TArray<AActor*>& ActorsToIgnore) const
140140
{
141-
const FVector Start = SpawnLocation + FVector(0, 0, 10.0f);
142-
const FVector End = SpawnLocation - FVector(0, 0, 20000.0f);
141+
const FVector Start = SpawnLocation + FVector(0, 0, 200.0f);
142+
const FVector End = SpawnLocation - FVector(0, 0, 10000.0f);
143143

144144
FHitResult HitResult;
145145
FCollisionQueryParams CollisionParams;
@@ -177,12 +177,45 @@ void ALargeMapManager::AdjustAllSignsToHeightGround()
177177
continue;
178178
if (TrafficSign->bPositioned)
179179
continue;
180-
FVector SpawnLocation = Actor->GetActorLocation();
181-
TrafficSign->bPositioned = AdjustSignHeightToGround(SpawnLocation, Actor->GetName(), ActorsToIgnore);
182-
183-
Actor->GetRootComponent()->SetMobility(EComponentMobility::Movable);
184-
Actor->SetActorLocation(SpawnLocation);
185-
Actor->GetRootComponent()->SetMobility(EComponentMobility::Static);
180+
FVector OriginalLocation = Actor->GetActorLocation();
181+
FVector AdjustedLocation = OriginalLocation;
182+
183+
TrafficSign->bPositioned = AdjustSignHeightToGround(AdjustedLocation, Actor->GetName(), ActorsToIgnore);
184+
185+
if (TrafficSign->bPositioned)
186+
{
187+
float ZOffset = AdjustedLocation.Z - OriginalLocation.Z;
188+
189+
Actor->GetRootComponent()->SetMobility(EComponentMobility::Movable);
190+
191+
// Get all static mesh components
192+
TArray<UStaticMeshComponent*> StaticMeshComps;
193+
Actor->GetComponents<UStaticMeshComponent>(StaticMeshComps);
194+
195+
for (UStaticMeshComponent* MeshComp : StaticMeshComps)
196+
{
197+
if (!MeshComp) continue;
198+
199+
// Skip if this has a mesh parent (it's a child)
200+
USceneComponent* ParentComp = MeshComp->GetAttachParent();
201+
if (ParentComp && Cast<UStaticMeshComponent>(ParentComp))
202+
{
203+
continue;
204+
}
205+
206+
// Move the mesh component down
207+
FVector CompLocation = MeshComp->GetRelativeLocation();
208+
CompLocation.Z += ZOffset;
209+
MeshComp->SetRelativeLocation(CompLocation);
210+
211+
MeshComp->UpdateBounds();
212+
213+
LM_LOG(Log, "Moved mesh %s by %f cm", *Actor->GetName(), ZOffset);
214+
}
215+
216+
Actor->UpdateComponentTransforms();
217+
Actor->GetRootComponent()->SetMobility(EComponentMobility::Static);
218+
}
186219
}
187220
}
188221

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightManager.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,50 @@ void ATrafficLightManager::AdjustAllSignsToHeightGround()
266266
{
267267
for(ATrafficSignBase* TS : TrafficSigns)
268268
{
269-
TS->GetRootComponent()->SetMobility(EComponentMobility::Movable);
270-
FVector SpawnLocation = TS->GetActorLocation();
271-
AdjustSignHeightToGround(SpawnLocation);
272-
TS->SetActorLocation(SpawnLocation);
273-
TS->GetRootComponent()->SetMobility(EComponentMobility::Static);
269+
if (!IsValid(TS))
270+
continue;
271+
if (TS->bPositioned)
272+
continue;
273+
274+
FVector OriginalLocation = TS->GetActorLocation();
275+
FVector AdjustedLocation = OriginalLocation;
276+
277+
TS->bPositioned = AdjustSignHeightToGround(AdjustedLocation);
278+
279+
if (TS->bPositioned)
280+
{
281+
float ZOffset = AdjustedLocation.Z - OriginalLocation.Z;
282+
283+
TS->GetRootComponent()->SetMobility(EComponentMobility::Movable);
284+
285+
// Get all static mesh components
286+
TArray<UStaticMeshComponent*> StaticMeshComps;
287+
TS->GetComponents<UStaticMeshComponent>(StaticMeshComps);
288+
289+
for (UStaticMeshComponent* MeshComp : StaticMeshComps)
290+
{
291+
if (!MeshComp) continue;
292+
293+
// Skip if this has a mesh parent (it's a child)
294+
USceneComponent* ParentComp = MeshComp->GetAttachParent();
295+
if (ParentComp && Cast<UStaticMeshComponent>(ParentComp))
296+
{
297+
continue;
298+
}
299+
300+
// Move the mesh component down
301+
FVector CompLocation = MeshComp->GetRelativeLocation();
302+
CompLocation.Z += ZOffset;
303+
MeshComp->SetRelativeLocation(CompLocation);
304+
305+
MeshComp->UpdateBounds();
306+
307+
UE_LOG(LogCarla, Log, TEXT("Moved mesh %s by %f cm"), *TS->GetName(), ZOffset);
308+
}
309+
310+
TS->UpdateComponentTransforms();
311+
TS->GetRootComponent()->SetMobility(EComponentMobility::Static);
312+
}
274313
}
275314
}
276315

@@ -909,7 +948,7 @@ void ATrafficLightManager::RemoveAttachedProps(TArray<AActor*> Actors) const
909948

910949
bool ATrafficLightManager::AdjustSignHeightToGround(FVector& SpawnLocation) const
911950
{
912-
const FVector Start = SpawnLocation + FVector(0, 0, 10.0f);
951+
const FVector Start = SpawnLocation + FVector(0, 0, 200.0f);
913952
const FVector End = SpawnLocation - FVector(0, 0, 10000.0f);
914953

915954
FHitResult HitResult;

0 commit comments

Comments
 (0)