x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Slate: How to pass a variable along in the OnClicked event for a button?

As the title says, I've got a button that I can click and a function is called - however, the OnClicked declaration shows a delegate to be passed with FReply as return value and no parameters.

Now it's absolutely essential that I can pass along a parameter to that delegate since I'm dynamically adding buttons while iterating through an array, and I need to pass a reference to the object in the array that the button represents so I can figure out which action to take.

Hopefully one of you guys have an answer to this :)

Thanks in advance!

Product Version: Not Selected
Tags:
more ▼

asked Mar 26 '14 at 10:42 PM in C++ Programming

avatar image

ReqPro
54 9 12 14

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

You're able to bind variables to a delegate; I can't remember the exact syntax when doing this inside Slate (nor the names of the delegate), but it would be something along the lines of:

 FOnClicked::CreateSP(this, &SMyWidget::OnClicked, MyVariableToBind)

MyVariableToBind would then be passed into SMyWidget::OnClicked as a parameter.

Slate might have the syntactic sugar to let you do that as (I'm not sure though, as I don't often have to bind variables to a delegate):

 .OnClicked(this, &SMyWidget::OnClicked, MyVariableToBind)

more ▼

answered Mar 26 '14 at 11:18 PM

avatar image

Jamie Dale STAFF
7.4k 176 66 304

avatar image ReqPro Mar 26 '14 at 11:37 PM

Thanks again, Jamie, you're a real lifesaver.

I actually tried something very similar to this but dcouldn't get it to work properly so I abandoned it - I must've messed up my pointer or something.

It works like a charm now, though.

Thanks again!

avatar image Timoses Aug 06 '15 at 04:39 PM

How would I go about passing a parameter from a UMG UButton? It has a dynamic multicast delegate (without parameters though).

avatar image WHSolv Jun 16 '17 at 10:26 AM

Make a custom delegate?..

avatar image Bertram.Sch Oct 30 '15 at 08:36 AM

This way works, but i needed some time to get it right, here is a longer description:

     FString f = FString("delegateString");
     FOnClicked::CreateSP(this, &SStandardSlateWidget::myFunc, f);
 
     SNew(SButton).OnClicked(this, &SStandardSlateWidget::myFunc, FString("OnClickedString"))

And the function:

 FReply SStandardSlateWidget::myFunc(FString myString)
 {
     if (GEngine)GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("f-delegate: %s"), *myString));
     return FReply::Handled();
 }
(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question