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"

Calling Blueprint Event from C++ code

Hi all,

i would like to call an event inside my HUD blueprint using C++.

So, basically, when the character take damage i want to remove some health from it and call the event UpdateHUD which redraw the hearts based on the health remaining. How can i achieve something like this?

 float AScrollerGameCharacter::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
 {
     this->Health--;
     return Damage;
 }


alt text

Product Version: UE 4.22
Tags:
untitled.png (366.6 kB)
more ▼

asked Jul 01 '19 at 10:26 PM in C++ Programming

avatar image

Fanto88
318 23 15 28

avatar image SupDeity Jul 02 '19 at 05:23 AM

i dont think you can call blueprint event from c++. the opposite is easy but i dont think there is even documentation about this.

avatar image GarnerP57 Jul 02 '19 at 07:32 AM

It can be done but is a hack more than a solution. You should instead make a Blueprint Implementable or Native Event.

avatar image Fanto88 Jul 02 '19 at 01:16 PM

So.. i've made some edits:

     UFUNCTION(BlueprintImplementableEvent)
         void UpdateHud();

Inside the Widget C++ parent class, and now i can correctly see the Event UpdateHud inside the UMG blueprint of the widget. But how can i call that event from another c++ class?

avatar image Fanto88 Jul 02 '19 at 02:20 PM

Nevermind, seems like i've fixed it with:

Inside the .h file:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = PlayerWidget)
 class UScrollerGameWidget* Widget;

Inside the .cpp file:

     this->Widget->RedrawHud();
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Nevermind, seems like i've fixed it with:

Inside the .h file:

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = PlayerWidget)
 class UScrollerGameWidget* Widget;

Inside the .cpp file:

     this->Widget->RedrawHud();
more ▼

answered Jul 09 '19 at 11:02 AM

avatar image

Fanto88
318 23 15 28

(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