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"

use of .OnCheckStateChanged

Hello community :)

I'm having troubles trying to call a function when the player check a check box.

Following the example of the StrategyGame that use .OnClicked(this, &SStrategyActionGrid::TriggerAction, i*GridRows+j) on a button I tried to do .OnCheckStateChanged(this, &SBookMarks::TextSelected) on my check box.

The function declaration goes like : FReply TextSelected() const;

And I'm getting : Error 1 error C2664: 'SCheckBox::FArguments::WidgetArgsType &SCheckBox::FArguments::OnCheckStateChanged(const FOnCheckStateChanged &)' : cannot convert argument 2 from 'FReply (__cdecl SBookMarks:: )(void) const' to 'void (__cdecl SBookMarks:: )(Param1Type)' C:\Users\Adinimys\Documents\Unreal Projects\MyProject6\Source\MyProject6\BookMarks.cpp 28

Additionaly, I noticed that even though the StrategyExample almost use "this" in the "parameters" (I don't know how is it called) of the widgets, the ShooterGame example do that really less often and I never used it in my own code that is working nonetheless (appart from the function call). Could someone explain my what is the point of "this" in that situation ? With slate documation currently returning a 404 error, the unique syntax of widgets is really tricky to understand :/

Thank you for answering my questions :)

Product Version: Not Selected
Tags:
more ▼

asked Nov 25 '14 at 10:37 AM in C++ Programming

avatar image

Adinimys
73 10 7 13

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi,

From the error you pasted I assume your SBookMarks::TextSelected looks like this:

 FReply SBookMarks::TextSelected()
 {
 /* your code here */
 }

this function can be used to create a delegate that will be called during SButton click (OnClicked) however SCheckBox::OnCheckStateChanged uses different function that returns nothing and takes one parameter, so your TextSelected function should look like this:

 void SBookMarks::TextSelected(ESlateCheckBoxState::Type InState)
     {
     /* your code here */
     }

About "this" keyword. I assume you know what it does (if not: http://www.cplusplus.com/forum/beginner/39333/).

So Slate widgets can have different type of parameters. Most common would be:

 SLATE_ARGUMENT() - use it if you want to specify parameter that will passed during creation time of a widget (i.e. IsFocusable flag on SButton)

 SLATE_ATTRIBUTE() - use it if you want to specify a dynamic parameter that will change during runtime (i.e. Text on STextBlock) 

 SLATE_EVENT() - simple event/delegate that can be executed later on.

If you go to SCheckBox.h file you can see that OnCheckStateChanged is actually SLATE_EVENT parameter so you will need to pass a pointer to a function that should be executed when "check state is changed".

Also, I would recommend going through examples stored in STestSuite.cpp and SWidgetGallery.cpp when it comes to basic stuff like this. Strategy/Shooter game examples are kinda more advanced and can be confusing if you're not at least somewhat familiar with Slate.

Hope this helps in some way.

more ▼

answered Nov 25 '14 at 05:50 PM

avatar image

szyszek
595 16 10 36

avatar image Adinimys Nov 25 '14 at 08:07 PM

Yes thanks a lot, I've been strugling with trying to call a function from widget during the whole day :D

I can't find STestSuite.cpp and SWidgetGallery.cpp, are they part of the engine source code (my subscription is currently canceled so I can't access it) ?

But about "this"... I understand what it does in regular c++ but not why we should use it as a parameter for the slate widgets :/

avatar image szyszek Nov 26 '14 at 08:52 AM

You can find those files under Engine\Source\Runtime\AppFramework\Private\Widgets\Testing

Taking SCheckBox::OnCheckStateChanged as an example: OnCheckStateChanged is a delegate, right? FOnCheckStateChanged (you can check it in SCheckBox.h). So what you have to do during creation of SCheckBox is pass a delegate that will be executed during CheckState change. You can create delegates in a few ways, the most clear one would be FOnCheckStateChanged::CreateRaw(...). CreateRaw will create a delegate using passed pointer to an object and its member function, like this:

 OnCheckStateChanged(FOnCheckStateChanged::CreateRaw(this, &SBookMarks::TextSelected))

Above code will work exactly the same like this one:

 OnCheckStateChanged(this, &SBookMarks::TextSelected)

So to create (raw) delegate you need have a pointer to an object ( this ) and a member function signature ( &SBookMarks::TextSelected )

So long story short, passing using OnCheckStateChanged(this, &SBookMarks::TextSelected) is just an implicit, shorter use for creating delegates. This way you dont really have to know the exact type of delegate (`FOnCheckStateChanged` in this case) to create your widget.

avatar image Adinimys Nov 26 '14 at 04:11 PM

Thank you :) I never though about searching in these folders ^^

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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