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"

Ue crashes on RebuildWidget in custom button class

I've created custom button class to have na opportunity to get clicked button reference onclick event. I did it like here
https://answers.unrealengine.com/questions/668694/how-to-pass-self-reference-to-ubuttons-onclicked-d.html
But UE4 crashes after function RebuildWidget finishes. I have no idea what to do in this case.
GoodButton.h

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonClickedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonPressedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonReleasedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonHoveredRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonUnhoveredRefDel, UGoodButton*, ButtonRef);
 
 UCLASS()
 class TESTPL_API UGoodButton : public UButton
 {
     GENERATED_BODY()
 public:
     UPROPERTY(BlueprintAssignable, Category = "Button|Event")
     FOnButtonClickedRefDel OnClickedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "Button|Event")
     FOnButtonPressedRefDel OnPressedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "Button|Event")
     FOnButtonReleasedRefDel OnReleasedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "Button|Event")
     FOnButtonHoveredRefDel OnHoveredReferenced;
     UPROPERTY(BlueprintAssignable, Category = "Button|Event")
     FOnButtonUnhoveredRefDel OnUnhoveredReferenced;
     
 protected:
     /** Handle the actual click event from slate and forward it on */
     FReply SlateHandleClicked();
     void SlateHandlePressed();
     void SlateHandleReleased();
     void SlateHandleHovered();
     void SlateHandleUnhovered();
 
 protected:
     //~ Begin UWidget Interface
     virtual TSharedRef<SWidget> <b>RebuildWidget()</b> override;
 #if WITH_EDITOR
     virtual TSharedRef<SWidget> RebuildDesignWidget(TSharedRef<SWidget> Content) override { return Content; }
 #endif
     //~ End UWidget Interface
 
 protected:
     /** Cached pointer to the underlying slate button owned by this UWidget */
     TSharedPtr<SButton> MyButton;
     
 };

GoodButton.cpp

 FReply UGoodButton::SlateHandleClicked()
 {
     OnClickedReferenced.Broadcast(this);
 
     return FReply::Handled();
 }
 
 void UGoodButton::SlateHandlePressed()
 {
     OnPressedReferenced.Broadcast(this);
 }
 
 void UGoodButton::SlateHandleReleased()
 {
     OnReleasedReferenced.Broadcast(this);
 }
 
 void UGoodButton::SlateHandleHovered()
 {
     OnHoveredReferenced.Broadcast(this);
 }
 
 void UGoodButton::SlateHandleUnhovered()
 {
     OnUnhoveredReferenced.Broadcast(this);
 }
 
 TSharedRef<SWidget> UGoodButton::RebuildWidget()
 {
     
     MyButton = SNew(SButton)
         .OnClicked(BIND_UOBJECT_DELEGATE(FOnClicked, SlateHandleClicked))
         .OnPressed(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandlePressed))
         .OnReleased(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandleReleased))
         .OnHovered_UObject(this, &UGoodButton::SlateHandleHovered)
         .OnUnhovered_UObject(this, &UGoodButton::SlateHandleUnhovered)
         .ButtonStyle(&WidgetStyle)
         .ClickMethod(ClickMethod)
         .TouchMethod(TouchMethod)
         .IsFocusable(IsFocusable)
         ;
 
     if (GetChildrenCount() > 0)
     {
         Cast<UButtonSlot>(GetContentSlot())->BuildSlot(MyButton.ToSharedRef());
     }
 
     return MyButton.ToSharedRef();
 }
 
Product Version: UE 4.20
Tags:
more ▼

asked Oct 20 '18 at 05:22 PM in C++ Programming

avatar image

AlexWrj
6 1 4

avatar image AlexWrj Oct 20 '18 at 05:40 PM

I used to try overriding RebuildWidget() from UButton. Crashes ended but I had no reaction, when clicked the button (I've binded it in derrived blueprint class). I only could trigger it manually.

      TSharedRef<SWidget> OurWidget = Super::RebuildWidget();
(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Got it! I declared multicast delegate for onUnHover event which was an ecxessable! So we only need 4 delegates:

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonClickedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonPressedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonReleasedRefDel, UGoodButton*, ButtonRef);
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnButtonHoveredRefDel, UGoodButton*, ButtonRef);

And 5 properties:

 UPROPERTY(BlueprintAssignable, Category = "GoodButton|Event")
     FOnButtonClickedRefDel OnClickedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "GoodButton|Event")
     FOnButtonPressedRefDel OnPressedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "GoodButton|Event")
     FOnButtonReleasedRefDel OnReleasedReferenced;
     UPROPERTY(BlueprintAssignable, Category = "GoodButton|Event")
     FOnButtonHoveredRefDel OnHoveredReferenced;
     UPROPERTY(BlueprintAssignable, Category = "GoodButton|Event")
     FOnButtonHoveredRefDel OnUnhoveredReferenced;
more ▼

answered Oct 21 '18 at 03:21 PM

avatar image

AlexWrj
6 1 4

(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