9 #include "Engine/StaticMeshActor.h" 15 auto StaticMeshDefinition = ABFL::MakeGenericDefinition(
19 StaticMeshDefinition.Class = AStaticMeshActor::StaticClass();
32 return { StaticMeshDefinition };
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);
Definition of an actor variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
FActorSpawnResult SpawnActor(const FTransform &SpawnAtTransform, const FActorDescription &ActorDescription) final
Spawn an actor based on ActorDescription and Transform.
TSubclassOf< AActor > Class
Class of the actor to be spawned.
A description of a Carla Actor with all its variation.
TArray< FActorDefinition > GetDefinitions() final
Retrieve the definitions of the static mesh actor.
Result of an actor spawn function.