36 const FTransform &SpawnAtTransform,
40 auto *World = GetWorld();
43 UE_LOG(LogCarla, Error, TEXT
44 (
"AStaticMeshFactory: cannot spawn mesh into an empty world."));
48 float Scale = ABFL::RetrieveActorAttributeToFloat(
"scale", ActorDescription.
Variations, 1.0f);
49 FTransform ScaledTransform(SpawnAtTransform);
50 ScaledTransform.SetScale3D(FVector(Scale));
52 FActorSpawnParameters SpawnParameters;
53 SpawnParameters.SpawnCollisionHandlingOverride =
54 ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
55 auto *StaticMeshActor = World->SpawnActor<AStaticMeshActor>(
56 ActorDescription.
Class, ScaledTransform, SpawnParameters);
58 auto *StaticMeshComponent = Cast<UStaticMeshComponent>(
59 StaticMeshActor->GetRootComponent());
61 if (StaticMeshComponent)
63 if (ActorDescription.
Variations.Contains(
"mesh_path"))
65 FString MeshPath = ABFL::ActorAttributeToString(
68 UStaticMesh *Mesh = LoadObject<UStaticMesh>(
nullptr, *MeshPath);
69 StaticMeshComponent->SetMobility(EComponentMobility::Movable);
70 if (!StaticMeshComponent->SetStaticMesh(Mesh))
71 UE_LOG(LogCarla, Warning, TEXT(
"Failed to set the mesh"));
72 StaticMeshComponent->SetMobility(EComponentMobility::Static);
74 if (ActorDescription.
Variations.Contains(
"mass"))
76 float Mass = ABFL::RetrieveActorAttributeToFloat(
"mass", ActorDescription.
Variations, 0.0f);
79 StaticMeshComponent->SetMobility(EComponentMobility::Movable);
80 StaticMeshComponent->SetSimulatePhysics(
true);
81 StaticMeshComponent->SetCollisionProfileName(
"PhysicsActor");
82 StaticMeshComponent->SetMassOverrideInKg(
"", Mass);