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"

OnClick Event Dynamic Button C++

Hi, I'm using the OnClick event that runs when I click my buttons. I am creating 3 bottones from my Blueprint Widget and I call them from my c ++ code with the UPROPERTY method (meta = (BindWidget)). Now what I want to achieve is to call each button from the same method to avoid creating each call event for each button. that is, dynamically. I already know that from my event I would have to use an "if" but I do not know how to get the button that is being called. Here is my code:

.h:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "CoreMinimal.h"
 #include "Blueprint/UserWidget.h"
 #include "MyUserWidget.generated.h"
 
 /**
  * 
  */
 
 UCLASS()
 class GAMEPARTY_API UMyUserWidget : public UUserWidget
 {
     GENERATED_BODY()
 
 public:
 
     virtual void NativeConstruct() override;
 
     UPROPERTY(meta = (BindWidget))
         class UButton* NewGame;
 
     UPROPERTY(meta = (BindWidget))
         class UButton* Options;
 
     UPROPERTY(meta = (BindWidget))
         class UButton* Exit;
 
     UFUNCTION()
         void OnMenuClick();
 };

.cpp:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "MyUserWidget.h"
 #include "UMG/Public/Components/Button.h"
 #include "UMG/Public/Components/TextBlock.h"
 #include "Engine.h"
 #include "MyGameUserSettings.h"
 
 void UMyUserWidget::NativeConstruct()
 {
     Super::NativeConstruct();
 
     NewGame->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);
     Options->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);
     Exit->OnClicked.AddDynamic(this, &UMyUserWidget::OnMenuClick);    
 }
 
 void UMyUserWidget::OnMenuClick()
 {
 
 }
Product Version: UE 4.22
Tags:
more ▼

asked May 29 '19 at 02:19 PM in C++ Programming

avatar image

danielf94
91 2 8 9

avatar image danielf94 Jun 21 '19 at 03:15 PM

I saw that with the unity graphics engine it is very easy to do it. There should be a way to apply it to the unreal

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

1 answer: sort voted first

Probably the only way is to make a derived class from `UButton` and add a new delegate with additional parameter so you can send the button id/name/something to distinguish different buttons.

more ▼

answered May 29 '19 at 08:51 PM

avatar image

norlin
440 11 18 27

avatar image danielf94 Jun 21 '19 at 03:13 PM

crash report, I see that the post is from 2015.

(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