From 009663e57d7b83d0caa4d4ffd2a54cb1734ec17b Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 2 Dec 2020 19:30:32 +0100 Subject: [PATCH] Added workarround to enable custom Carsim simfile. --- .../Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 051f5e505..81842f672 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -558,13 +558,17 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath) CarSimMovementComponent->DisableVehicle = false; CarSimMovementComponent->VsConfigFile = SimfilePath; CarSimMovementComponent->Activate(); + // super hack to work arround CarSim component limitations to specify simfiles + CarSimMovementComponent->EndPlay(EEndPlayReason::Type::RemovedFromWorld); + CarSimMovementComponent->BeginPlay(); + CarSimMovementComponent->ResetVsVehicle(false); // set carsim position to actor's CarSimMovementComponent->SyncVsVehicleLocOri(); CarSimMovementComponent->SetComponentTickEnabled(true); // set kinematic mode for root component and bones GetMesh()->PhysicsTransformUpdateMode = EPhysicsTransformUpdateMode::ComponentTransformIsKinematic; - auto * Bone = GetMesh()->GetBodyInstance("Vehicle_Base"); + auto * Bone = GetMesh()->GetBodyInstance(NAME_None); if (Bone) { Bone->SetInstanceSimulatePhysics(false); @@ -586,7 +590,7 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath) CarSimMovementComponent->Deactivate(); CarSimMovementComponent->VsConfigFile = ""; GetMesh()->PhysicsTransformUpdateMode = EPhysicsTransformUpdateMode::SimulationUpatesComponentTransform; - auto * Bone = GetMesh()->GetBodyInstance("Vehicle_Base"); + auto * Bone = GetMesh()->GetBodyInstance(NAME_None); if (Bone) { Bone->SetInstanceSimulatePhysics(true); @@ -598,6 +602,7 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath) OnActorHit.RemoveDynamic(this, &ACarlaWheeledVehicle::OnCarSimHit); GetMesh()->OnComponentBeginOverlap.RemoveDynamic(this, &ACarlaWheeledVehicle::OnCarSimOverlap); GetMesh()->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Block); + GetMesh()->SetCollisionProfileName("Vehicle"); } bCarSimEnabled = bEnabled; }