Write objects into data asset ?

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;
}`

Steps to Reproduce

  • Open the Tool
  • Choose an object and press on of the Create light button. For Example Create Custom Light or 3PointLightPrefab
  • Then select the created lights and use the button “Save Selected Spotlights to DataAsset” (UI is not great strucktured sorry for that^^)
  • Open the Da_liughts data asset and try to save it.
  • Sometimes i get an error and sometimes the light saved but if i reopen the project the data asset is emtpy again.

Hi there,

Just for my clarification, you are looking for a way to save light settings and copy those settings onto other lights, as well as save those settings for re-use.

From looking at the code, it looks like you are storing pointers to the instance created within a level and attempting to save that array of pointers. Once that level has been unloaded, those pointers would no longer be valid. You might be able to achieve this with soft object pointers, but I wouldn’t recommend this. Within your tool blueprint, you store the values you care about into a blueprint struct with the values you care about, color intensity, etc, and save that into the data asset.

Instead, I think you could achieve this in a few other ways.

You could create blueprints of the lights that you create and then spawn or replace actors in place with these lights. You can convert instances of lights to a blueprint by clicking the convert to blueprint button, and replace existing lights with the “replace selected actors with…” context menu.

[Image Removed]

There is also a plugin in the engine that you can enable called “actor palette”, which allows you to open another level to act as a palette or showcase level. That allows you to sample actors from another level and drag them into the current level. This would allow you to store a set of lights and reuse them at will.

Further, there are a couple of tools within the editor [Window] menu, the Light Mixer and the Environment Light Mixer, which may provide some of the tooling you are looking for. See the Light Mixer Documentation: https://dev.epicgames.com/documentation/en\-us/unreal\-engine/using\-the\-light\-mixer\-in\-unreal\-engine

[Image Removed]

If there is any further information I can provide, please let me know.

Kind Regards

Keegan Gibson

Thank you for the Information. These tool are certainly useful. I will look into the option of “create blueprints”. Could work as kind of prefab solution.

But to create a Struc out of all Light Information could work as well for my little situation.

Thank i will look into these option. I Think this ticket can be closed for now. i know my next directions

No problem, I’ll close this ticket out for now. If you have any more questions, please create a new support request.