How to set a slate attribute dynamically

Hello, I have made a custom slate widget. It has a TAttribute which I want to set each time I create the slate widget. Something like this

class SURVIVALGAME_API SItemWidget : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SItemWidget)
		:_GameHUD()
	{}
	SLATE_ARGUMENT(TWeakObjectPtr<class ATestHUD>, GameHUD)
	SLATE_ATTRIBUTE(int32, Test)

	SLATE_END_ARGS()

public:
	/** Constructs this widget with InArgs */
	void Construct(const FArguments& InArgs);

private:
	TWeakObjectPtr<class ATestHUD> GameHUD;

	TAttribute<int32> Test;

	TWeakObjectPtr<class ATestHUD> ParentInventoryWidget;
};

I create this slate widget inside another slate widget something like this

	TSharedPtr<SVerticalBox> Col;
	SAssignNew(Col, SVerticalBox);
	for (int32 i = 0; i < 4; i++)
	{
		Col->AddSlot()
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Fill)
		[
			SNew(SItemWidget)
			.GameHUD(GameHUD)
			.Test(i)
		];
	}

But when I access the slate values all values appear to be zeros

	ChildSlot
	[
		SNew(SBox)
		.Padding(5)
		.HeightOverride(100)
		.WidthOverride(100)
		[
			SNew(SBox)
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Center)
			[
				SNew(STextBlock)
				.Text(FText::FromString(FString::FromInt(Test.Get())))
			]
		]
	];

But this doesn’t work and all values appear to be zeroes.

Hi,

you need to assign parameter value to actual class member, Slate wont do that for you. So at the beginning of Construct function put this:

Test = InArgs._Test;

Cheers

Thanks… works…

Although I have 2 simple questions…

Whats the difference between SLATE_ATTRIBUTE() and SLATE_ARGUMENT() and when should I use which?

And is it possible to change the value of test during run time by the use of a simple function?

For anyone finding this question:

These last 2 questions were answered at length in this related forums post.