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"

Run function, from panel customization, in Editor

My goal is a stats sheet ActorComponent with a button that recalculates the total stats (which are then displayed in the detail panel).
EG. (Constitution and Health Bonus are editable, Health Total is read-only)
Constitution: 5 Health Bonus: 5 Health Total: 50 (not-updated)
press button
Constitution: 5 Health Bonus: 5 Health Total: 55 (updated)

relevant code:
(MyStatsCustomization)

 TArray< TWeakObjectPtr<UObject> > objects;

 DetailBuilder.GetObjectsBeingCustomized(objects);
 [...]
     IDetailCategoryBuilder& Category = DetailBuilder.EditCategory("Object", FText::FromString("Getting Object"), ECategoryPriority::Important);
     UMyStats* stats= Cast<UMyStats>(objects[0].Get());
     if (stats != nullptr)
     {
         Category.AddCustomRow(LOCTEXT("Success", "Success"))
             .NameContent()
             [
                 SNew(SButton)
                 .Text(LOCTEXT("Test", "Test"))
                 //.OnClicked(*stats,&UMyStats::TestFunc)  //could not get OnClicked() to work at all
                 //.OnClicked(MyStatsCustomization::TestFunc)
                 .OnClicked_Lambda([&stats]()->FReply{ stats->TestFunc(); return FReply::Handled(); })
             ];
     }


(MyStats)

 UPROPERTY(EditAnywhere, EditFixedSize, BlueprintReadWrite)
     TArray<uint8> Attributes;
 void TestFunc() { Attributes[0] += 1; }


Attributes[0] should exist by this point; the array is filled in the constructor. Everything so far seemed to work until I actually click the button, at which point Unreal crashes with
Access violation - code c0000005 (first/second chance not available)

Retested replacing the contents of TestFunc() with
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!"));
Didn't crash, but also didn't display message.

EDIT: further testing:
UE_LOG does work, so the function is being called. However any attempt to modify a member variable (property or not) crashes Unreal with the error message above.

EDIT 2: further testing has revealed that "stats" above isn't pointing to the currently selected UMyStats the way I thought it was, which explains why accessing the variables failed. Can anyone explain how to call a function on the object being customized? Yet further tests show that the pointer isn't making it through the lambda function.

Also, Epic, if you're reading this: update the blasted tutorials. Like I said above, I couldn't get .OnClicked() to work at all.

Product Version: UE 4.9
Tags:
more ▼

asked Sep 03 '15 at 04:12 PM in C++ Programming

avatar image

NullBlack
110 8 10 14

avatar image Shadowriver Sep 03 '15 at 04:33 PM
 OnClicked(*stats,&UMyStats::TestFunc)

Why you using "*" here? you sould give pointer

avatar image NullBlack Sep 03 '15 at 04:36 PM

because that was the last iteration of "throw in an asterisk or ampersand to see if it stops complaining" before I commented out the line and tried something different.
Unless you can explain how to make .OnClicked() work, ignore the commented-out lines.

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

1 answer: sort voted first

 .OnClicked_UObject(stats, &UMyStats::TestFunc)

 [...]

 FReply TestFunc() { Attributes[0] += 1; return FReply::Handled(); }

Epic, would you kindly document your code? The API on the wiki makes no mention of the various OnClicked functions.

more ▼

answered Sep 04 '15 at 03:12 PM

avatar image

NullBlack
110 8 10 14

(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