I am trying to create a simulation where the user can drive a car around a map. The car will be equipped with various sensors (example: camera, radar, lidar, …). I have been able to create the sensor by placing using a 2D scene capture. This works great and all but I want to create some way of defining the number and position of the scene captures through a configuration file of some sort. I am not sure how to go about creating such a file or what code I would need to process the file and place the scene captures on the vehicle blue print at run time.
Edit:
I’ve gotten everything to work thanks to the discussion bellow, however I get an error when trying to spawn the SceneCapture during runtime. The code is
USceneCaptureComponent2D *sceneCaptureActor = (class USceneCaptureComponent2D *)GetWorld()->SpawnActor<USceneCaptureComponent2D>(USceneCaptureComponent2D::StaticClass());
which ends up returning a nullptr and printing error
LogSpawn: Warning: SpawnActor failed because SceneCaptureComponent2D is not an actor class
Not sure what to do about it.
Also, I updated the sensor config to
UENUM()
enum SensorType { RADAR, LIDAR };
UCLASS(config = Game)
class USensorPlacementConfigData : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float rot_x;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float rot_y;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float rot_z;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float rot_w;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float scale_x;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float scale_y;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float scale_z;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float trans_x;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float trans_y;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
float trans_z;
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
TEnumAsByte<SensorType> type;
};
and tried using a config called DefaultSensorPlacementConfigData.ini
[Script/<WATOSIM_API>.USensorPlacementConfigData]
rot_x=0,
rot_y=0,
rot_z=0,
rot_w=0,
scale_x=0,
scale_y=0,
scale_z=0,
trans_x=0,
trans_y=0,
trans_z=100,
type="USensorPlacementConfigData::SensorType::RADAR"
When looking in at the blueprint in ue4 I see the default value for the array of sensors and added a sensor
But when printing the values in c++ they are all 0. Not sure why that is or how to get my values showing up.
To recap please help with SceneCapture spawn problem and config values not being set properly.
Suggestions Tried:
Tried using a struct instead of class for config object. Here is my final attempt, I fiddled a bunch with it and couldn’t get it to build
USTRUCT()
struct FSensorPlacementConfigData
{
GENERATED_BODY()
public:
UPROPERTY( )
float rot_x;
UPROPERTY()
float rot_y;
UPROPERTY( )
float rot_z;
UPROPERTY( )
float rot_w;
UPROPERTY( )
float scale_x;
UPROPERTY( )
float scale_y;
UPROPERTY( )
float scale_z;
UPROPERTY( )
float trans_x;
UPROPERTY( )
float trans_y;
UPROPERTY( )
float trans_z;
UPROPERTY( )
TEnumAsByte<SensorType> type;
};
class API ASensorMountedVehicle : public AWheeledVehicle
{
GENERATED_BODY()
public:
UPROPERTY(Config, BlueprintReadWrite, EditAnywhere)
TArray<struct FSensorPlacementConfigData > sensors;
}
The error produced at the “sensors” line is
Error: Type ‘TArray’ is not supported by blueprint. SensorMountedVehicle.sensors