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"

How to create a basic health bar using C++?

Hi I am trying to build a game in C++. But, I am having trouble finding a video tutorial. Can someone tell me how to create a basic health bar using C++? Also, some info on how to damage the player with a fire would be helpful.

Product Version: UE 4.20
Tags:
more ▼

asked Apr 17 '19 at 02:18 AM in C++ Programming

avatar image

Ace-Hand-7333
1 1 2

avatar image Rejji Apr 17 '19 at 06:05 PM

Have you looked at the UE4 Gameplay Ability System?

https://docs.unrealengine.com/en-us/Gameplay/GameplayAbilitySystem

Epic provides an entire sample project that details how to use it. It covers a HUD system and damage to player with fire etc.:

https://www.youtube.com/watch?v=x5KqpYX4H6g&t=5s

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

1 answer: sort voted first

Creating a health bar purely in C++ makes little sense what i would suggest to you is create your health system entirly in C++ add some assignable MulticastDelegate on change to the health system and create a health bar widget in the editor which you can attach to the hud which registers itself to that health system and on change shows the current state.

For the delegate I would suggest something like that: DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHealthChanged, float, currentHealthInPercent, float, oldHealthInPercent);

and as member variable: UPROPERTY(BlueprintAssignable) FOnHealthChanged OnHealthChanged;

To damage a player with fire I would use an overlap volume and while the fire is burning and the player is inside this volume you apply damage to the player.

there are callbacks to OnComponentBeginOverlap OnComponentEndOverlap to find out when a player enters, leaves a volume.

more ▼

answered Apr 17 '19 at 06:07 AM

avatar image

Lardo Deepdelver
786 5 4 6

avatar image Ace-Hand-7333 Apr 17 '19 at 03:40 PM

Thank you for your response. This is my first C++ game. So the more details that you can give me would be extremely helpful. I have created games with blueprints but I am trying to create this game with C++. and I can not find either Unreal video tutorials or documentation on creating a HUD.

avatar image Nebula Games Inc Apr 17 '19 at 05:25 PM

I believe that is because creating a HUD in C++ is more effort than its worth. UMG is very nice to use and easy for creating widgets. I have some tutorials (mainly for blueprint minded people where I modify and change progress bars in C++). I provide new nodes for use in blueprints but you may be more interested in looking at the source code to see how I was able to do certain things. If you are familiar with blueprint nodes, they are all functions available in C++ some just have slightly different names and you have to find the correct header files to use them. Anyway, below is a link to a bunch of nodes I made using C++ a few deal with progress bars specifically.

https://www.youtube.com/playlist?list=PLyu-W38DvZhqOdaCkB4hGWYQzuKH2gALZ

(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