So I’ve been trying to learn Slate recently, and I guess the next step is to update data during gameplay (rather than keep it as it was when it was initialized), so I tried:
-Passing a function pointer (the address of the function, namely &SMyWidget::GetValue
style syntax)
-Creating a delegate:
DECLARE_DELEGATE_RetVal(FString, fstringdellegate);
fstringdellegate del;
del.BindSP(this,&SMyWidget::getFocusedItemNameS);
-Using TAttribute
, which actually seemed to be the most reasonable to me:
TAttribute<FString> Value = TAttribute<FString>::Create(TAttribute<FString>::FGetter::CreateUObject(this, &SMyWidget::getFocusedItemNameS));
In each and every caseI got errors related to syntax generally. Here’s where I want to put the text:
.Text(this, /*can you get a bleeping update-able value in here??*/)
So, is there any hope? Can anyone provide an appropriate syntax to match either of these methods to get that variable in there? I’d be delighted to have an answer for each method, but I’ll settle for one that works.
Many thanks in advance, cheers!
Edit: The structure is as follows:
MyWidget.h:
public:
SLATE_BEGIN_ARGS(SMyWidget)
{}
SLATE_ARGUMENT(TWeakObjectPtr<class AMainHUD>, OwnerHUD)
SLATE_END_ARGS()
/** Constructs this widget with InArgs */
void Construct(const FArguments& InArgs);
private:
TWeakObjectPtr<class AMainHUD> OwnerHUD;
AMyProjectCharacter* character;
FText getFocusedItemName();
FString SMyWidget::getFocusedItemNameS();
I set the character through this sequence, which has so far brought back the right strings, so it should still be accessing the only character:
TArray<APlayerController*, FDefaultAllocator> controllers;
GEngine->GetAllLocalPlayerControllers(controllers);
character = (AMyProjectCharacter*)(controllers[0]->GetPawn());
From here on, I’ve got a function returning FString, and a near identical one returning FText (I made sure they return the right thing and their names are different) getting a string from the character, which changes during gameplay.
Initialization of the widget works perfectly fine, I’m only changing the text it displays.