OnDataTableChanged can't support modify child Tarray Data

I have a FTableRowBase struct Like

struct FMarketData : public FTableRowBase
{
  virtual void OnDataTableChanged(const UDataTable* InDataTable, const FName InRowName) override;

   FName ItemName

   TArray<FConsume> PayConditions;
}

which struct has a Tarray data PayConditions

struct FConsume
{
	GENERATED_USTRUCT_BODY()

public:
	FConsume(){}
	
	UPROPERTY(EditAnywhere, BlueprintReadOnly)
	FName ItemID;

	//Only Preview
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	FName ConsumeItemName;
}

when I use OnDataTableChanged to change PayConditions.ItemName

if restart engine, the data ConsumeItemName will be removed, is NONE . but ItemName is correct

what’s happen?

It seems that the ConsumeItemName property is only marked as VisibleAnywhere but not as EditAnywhere. The EditAnywhere attribute makes the property editable in the Unreal Editor and is required to persist the value when the game or engine is restarted.

To fix this issue, you can add the EditAnywhere attribute to the ConsumeItemName property in the FConsume struct.

If this doesn’t fix the issue, perhaps there is a saving issue causing the data to be removed.

This topic has been moved from International to Programming & Scripting: C++.

When posting, please review the categories to ensure your topic is posted in the most relevant space.

Thanks and happy developing! :slight_smile:

sorry, EditAnywhere can’t solve it :smiling_face_with_tear:

The OnDataTableChanged function is called whenever the underlying data in a UDataTable changes, but it does not provide a mechanism for modifying the data stored in the PayConditions array.

To modify the data stored in the PayConditions array, you would need to write code that updates the values of the FConsume structs in the array directly. This can be done either in the OnDataTableChanged function or in another function that is called when you want to update the data.

For example, you could add a function to the FMarketData struct that updates the ConsumeItemName property of all the FConsume structs in the PayConditions array:

c

void FMarketData::UpdateConsumeItemNames(const FName NewConsumeItemName)
{
    for (FConsume& Consume : PayConditions)
    {
        Consume.ConsumeItemName = NewConsumeItemName;
    }
}

This function would take a FName parameter that specifies the new value to set for the ConsumeItemName property. You would call this function whenever you need to update the ConsumeItemName values in the PayConditions array.

Let me know if this helps you out?

1 Like

thanks for you help, it’s really useful

Awesome! Glad I could help! :slight_smile: