CARLA
Loading...
Searching...
No Matches
PropActorFactory.h
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#pragma once
8
12
13#include <util/ue-header-guard-begin.h>
14#include "Json.h"
15#include "JsonUtilities.h"
16#include <util/ue-header-guard-end.h>
17
18#include "PropActorFactory.generated.h"
19
20UCLASS()
21class CARLA_API APropActorFactory : public ACarlaActorFactory
22{
23 GENERATED_BODY()
24
25 /// Retrieve the definitions of the static mesh actor
26 virtual TArray<FActorDefinition> GetDefinitions() override;
27
28 virtual FActorSpawnResult SpawnActor(
29 const FTransform &SpawnAtTransform,
30 const FActorDescription &ActorDescription) override;
31
32public:
33 UFUNCTION(BlueprintCallable, Category = "PropActorFactory")
34 static void SavePropParametersArrayToFile(const TArray<FPropParameters> &PropParamsArray, const FString &FileName);
35 UFUNCTION(BlueprintCallable, Category = "PropActorFactory")
36 static void LoadPropParametersArrayFromFile(const FString &FileName, TArray<FPropParameters> &OutPropParamsArray);
37
38 UFUNCTION(BlueprintImplementableEvent, Category = "PropActorFactory")
39 bool PostProcessProp(AActor* SpawnedActor, const FActorDescription& PropParams);
40
41private:
42 static TSharedPtr<FJsonObject> FPropParametersToJsonObject(const FPropParameters& PropParams);
43 static FString FPropParametersArrayToJson(const TArray<FPropParameters>& PropParamsArray);
44 static bool JsonToFPropParameters(const TSharedPtr<FJsonObject> JsonObject, FPropParameters& OutPropParams);
45 static bool JsonToFPropParametersArray(const FString& JsonString, TArray<FPropParameters>& OutPropParamsArray);
46
47 virtual void ReleaseContentPack(const FString &MountPoint) override;
48
49protected:
50 // Transient: GetDefinitions() rebuilds these from the JSON catalogs every
51 // episode, and a saved copy bakes a stale catalog into the map.
52 UPROPERTY(EditAnywhere, Transient)
53 TArray<FActorDefinition> Definitions;
54 UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient)
55 TArray<FPropParameters> PropsParams;
56
57private:
58 /// Mesh cache keyed by mesh path (same string stored in
59 /// ActorDescription.Variations["mesh_path"]). Populated from PropsParams in
60 /// GetDefinitions() so that SpawnActor() avoids the per-spawn
61 /// synchronous LoadObject on the game thread. Cache-miss fall back to
62 /// LoadObject with a warning log.
63 UPROPERTY(Transient, DuplicateTransient)
64 TMap<FString, TObjectPtr<UStaticMesh>> MeshCacheByPath;
65};
Base class for Carla actor factories.
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
Result of an actor spawn function.