Download

How can I create and serialize my Multi Dimensional Arrays?

I have a firearm with several parts that I’m trying to serialize. The difficult part is each part can have X number of parts, and those can in theory also have X number of parts. Basically this is an example of how it could go where the firearm has its parts, then parts like the handguard can have multiple parts, and those parts can also have parts and so on.

firearm
{
    handguard
    {
        45Offset
        {
            LightLaser
            {
                AnotherRandomAttachment
                {
                }
            }
        }
        ForwardGrip
        {
        }
    }
    barrel
    {
        Muzzle
        {
        }
    }
    PistolGrip
    {
    }
}

I am trying to figure out how to set this up via USTRUCTS using UPROPERTIES since I do need to serialize this for storage. I know USTRUCTS that have UPROPERTIES set do not like multi dimensional arrays so I tried with this route and have seem to come to a mental blocker and cannot think of a route to go for this. The firearm parts are setup in terms of components so the firearm for example has a component and I name it FPSTemplate_Handguard, that handguard has the handguard part on it (AFPSTemplate_PartBase) and then that handguard as shown in the example above can have multiple parts on it and then those parts can have parts and so on.

USTRUCT(BlueprintType)
struct FPartDataBase
{
    GENERATED_BODY()    
    UPROPERTY(BlueprintReadOnly)
    TSubclassOf<AFPSTemplate_PartBase> PartClass;
    UPROPERTY(BlueprintReadOnly)
    FString PartComponentName;
};

USTRUCT(BlueprintType)
struct FPartData
{
    GENERATED_BODY()
    UPROPERTY(BlueprintReadOnly)
    TArray<FPartDataBase> PartDatas;
};

USTRUCT(BlueprintType)
struct FFirearmData
{
    GENERATED_BODY()
    UPROPERTY(BlueprintReadOnly)
    TSubclassOf<AFPSTemplateFirearm> FirearmClass;
    UPROPERTY(BlueprintReadOnly)
    TArray<FPartData> PartComponents;
};

I just cannot think of a way to handle this. I currently already have it setup to serialize the firearm and its default parts and then each additional attachment which outputs the result like this which contains the basic parts, but on the handguard I attach a 45Offset mount, then on that I attach a lightlaser, then ontop of the lightlaser another lightlaser, then ontop of that another lightlaser just for the example. I need to set this up so I can deserialize it later on and reconstruct it to rebuild the firearm with all of the parts

{
	"firearmClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/Firearms/M4/BP_M4_Stripped.BP_M4_Stripped_C'",
	"partComponents": [
		{
			"partDatas": [
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/Firearms/M4/Parts/Barrels/BP_M4Barrel_10in.BP_M4Barrel_10in_C'",
					"partComponentName": "FPSTemplate_Barrel"
				},
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/FirearmParts/MuzzleDevices/BP_Suppressor.BP_Suppressor_C'",
					"partComponentName": "FPSTemplate_Muzzle"
				}
			]
		},
		{
			"partDatas": [
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/Firearms/M4/Parts/Handguards/BP_Handguard_10in.BP_Handguard_10in_C'",
					"partComponentName": "FPSTemplate_Handguard"
				},
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/FirearmParts/BP_45Offset.BP_45Offset_C'",
					"partComponentName": "FPSTemplate_45Offset"
				},
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/FirearmParts/BP_LightLaser.BP_LightLaser_C'",
					"partComponentName": "FPSTemplate_LightLaser"
				},
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/FirearmParts/BP_LightLaser.BP_LightLaser_C'",
					"partComponentName": "FPSTemplate_LightLaser"
				},
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/FirearmParts/BP_LightLaser.BP_LightLaser_C'",
					"partComponentName": "FPSTemplate_LightLaser"
				}
			]
		},
		{
			"partDatas": [
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/Firearms/M4/Parts/BP_M4_PistolGrip.BP_M4_PistolGrip_C'",
					"partComponentName": "FPSTemplate_PistolGrip"
				}
			]
		},
		{
			"partDatas": [
				{
					"partClass": "BlueprintGeneratedClass'/UltimateFPSTemplate/Firearms/M4/Parts/BP_M4_ChargingHandle.BP_M4_ChargingHandle_C'",
					"partComponentName": "FPSTemplate_ChargingHandle"
				}
			]
		}
	]
}