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.