good day,
Here i wanted to create a LightTool, that can help me create differnt kind of lights.
the creation and copying values from one light to another works. The only Thing that i wanted to do is to save light setting. I thought i could do that with a data asset. So i made a C++ Struc With a Map ID -> Spotlight. and the data asset saves then a array of Spotlights.
i can add spotlights via hand/manual. But everytime i want to write into this files it wont save. The information and correct lights are there but it gives an error when i want to Save it.
How can i write Objects into this data asset ? And Save them after the close of the programm.
i tried the ULightComponent as well as the ASpotlight
[Image Removed]
[Image Removed]
`#pragma once
include “CoreMinimal.h”
include “Engine/DataAsset.h”
include “Engine/SpotLight.h”
include “Components/LightComponent.h”
include “DA_LightSetups.generated.h”
/**
*
/
USTRUCT(BlueprintType)
struct TOOLTEST_API FLightarray {
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<ULightComponent> ArraysOfLights;
};
UCLASS()
class TOOLTEST_API UDA_LightSetups : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
// Data Asset array
// Struck ID
// Light Array
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TMap<int,FLightarray> ArraysOfStruc;
UFUNCTION(BlueprintCallable,Category = “LightSetups”)
TArray<ULightComponent*> GetLightArray(int Id);
UFUNCTION(BlueprintCallable, Category = “LightSetups”)
bool SetLightArray(int Id, TArray<ULightComponent*> ArraySpots);
UFUNCTION(BlueprintCallable, Category = “LightSetups”)
int GetAssetLength();
};
include “DA_LightSetups.h”
TArray<ULightComponent*> UDA_LightSetups::GetLightArray(int Id) {
TArray Keys;
ArraysOfStruc.GetKeys(Keys);
if (!Keys.Contains(Id))
{
return TArray<ULightComponent*>();
}
FLightarray Array = ArraysOfStruc[Id];
return Array.ArraysOfLights;
}
int UDA_LightSetups::GetAssetLength()
{
return ArraysOfStruc.Num();
}
bool UDA_LightSetups::SetLightArray(int Id, TArray<ULightComponent*> ArraySpots)
{
TArray Keys;
ArraysOfStruc.GetKeys(Keys);
if (Keys.Contains(Id))
{
return false;
}
FLightarray Array;
Array.ArraysOfLights = ArraySpots;
ArraysOfStruc.Add(Id, Array);
return true;
}`