Download

Experience System with working HUD

This is my tutorial for creating a fully functional experience system based on the tutorial I used in UDK. This system was originally created, as far as I can tell, by MKTWO in the following thread: Experience-system - Epic Games Forums. I cannot claim this to be original work but just adapted from this person.

Please be aware this took quite a bit of effort to write out and is only the second tutorial like document I’ve written. If I have made mistakes please let me know and I will do my best to fix them.

Before we start, I did hijack a couple things from the content example pack from the HUD level. You will need to **MIGRATE **the following items unless you know how to work material editor, which I don’t really yet. I highly suggest watching Unreal’s Youtube videos for materials found here: https://www.youtube.com/playlist?list=PLZlv_N0_O1gaCL2XjKluO7N2Pmmw9pvhE

Items to migrate:

  • T_HUD_Bar_Generic (Texture2D)
    
  • Health_Bar (Material)
    
  • Change the name of this file once you migrate it to EXP_BAR so not be confused by later references
    

You will need to alter the exp bar material just slightly but it should be easy enough.
When you open the material editor move to the far left and highlight the top parameter going to the CLAMP function and change its Parameter name to “Gathered EXP”
Change the parameter below that one to “Needed EXP”
9212f943a7660278ed32835caba9c4a9c38c6342.jpeg

Then you can set the two colors along the top to whatever colors you want your experience bar to be. The color on the left is the Current value of the bar while the other color is the missing value of the bar. You can get kind of creative here and make all sorts of combos. (great for doing Health, Mana, Experience, or whatever other bar needs to show on screen)
5389fff4c8d4e3cfd4d6843ba0ae0a5cdc590634.png

Last but not least, set the two texture samples in the bottom middle to the other material you migrated over (T_HUD_Bar_Generic)
[/LIST]

Interface
For this project the only interface we will need is very basic.
Right click in the content browser.
Select Blueprint interface under the miscellaneous selection

  1. Mine is named Experience

Once you open it, create a new function (Get Player Experience)
Create the following variables in the Outputs category (note they are all integers)

  1. EXP IN – This is how much experience you are feeding into the bar
  2. XP to Current Level
  3. XP Gathered for Next Level
  4. XP Required for Next Level
  5. Level
  6. Max Level

That should do it for now though we will revisit these variables in a bit.

HUD
Create a hud.

  1. Right click content browser, create new blueprint, search the custom classes for HUD.
  2. I named it MyHUD though name it whatever you’d like.

Assign your game blueprint to use this HUD.

  1. Open MyGame BP and assign it there.

Create the following variables inside the HUD (Type, Name)

  1. Vector 2D – Screen Dimensions
  2. Bool – Menu Open
  3. Object’MaterialinstanceDynamic’ – Experience Bar

In the construction script (Missing this step made me take forever to figure this whole thing out)

  1. Set up the following graph. This is just setting the material we will use for the bar itself

922956efa8c78fa66e1d30d4476b2fce23360b37.png

In the event graph let’s set up the first part of the nodes. This just gets us the users screen size for later reference. The branch is not used in this tutorial but would be used in another project to pause the game if a menu was open. Since I plan to add that functionality later I included it in this tutorial.
4e64d92c88ad3c977cb23aedafbb48fa48cd1609.png

For the next step, we need to enable the interface we created earlier.

  1. Click Blueprint Props below the menu bar along the top of the screen.
  2. In the bottom left under the interfaces section click Add -> Experience_C

For whatever reason at this point I had to close / re-open my project to get the interface to populate right. May have to do the same.

  1. NOTE: these will not work as intended yet since we have not set their values, we will do that when we visit our Pawn B

This next part gets kind of annoy because of where you have to drag your points from.

Here is how it should look when the HUD is all said and done.
07c05c337e9ff1a50f0fe8d3cf19aa4b785fa35c.jpeg

These steps are just to help set up the above image.

  1. When you try to get the “Get Player Experience” Function, please make sure if you are searching for it from the node menu that you select the one under the Interface Messages category. If you do not, you will not be able to correctly set the target to “Get player character”
  2. Set your Experience bar on the black board and drag from it to get the correct “Set Scalar Parameter value”

Get Player Experience

  1. This is pretty easy, this gets the values we will assign in our pawn BP and passes them into our HUD BP for use.

Set Scalar Parameter Value 1

  1. This finds the experience bar dynamic material we set in the construction script
  2. Then it gets the parameter name we set for how much exp our pawn has
  3. Then it gets the value from our interface

Set Scalar Parameter Value 2

  1. Same as before but it grabs the parameter name and value for how much exp our pawn still needs

Draw Material Simple

  1. Material – this gets the material we defined in the material editor earlier that we migrated from the other project
  2. Screen Y – -20
  3. Screen H – 30

Draw Text

  1. Text – Kind of long winded but just makes it show your experience nicely centered in the middle of your experience bar.
  2. Color – I suggest setting it to something that stands out against the colors you chose for your experience bar.
  3. Screen X – Dividing it by 2 centers it on your screen
  4. Screen Y - -20

That should do it for this section

Player Pawn (MyCharacter)
Enable the interface on this blueprint
Create the following variables:

  1. EXP

  2. XP to Current Level

  3. XP Gathered for Next Level

  4. XP Required for Next Level

  5. Level (0)

  6. Max Level (100)

  7. EXP Increment (500)

  8. Only EXP Increment is a float, the rest are integers.

  9. Create the following function or macros, whichever you prefer to use.

  10. Give Experience – We call this whenever the player should be given experience

  11. Inputs (Type,Name)

  12. Integer – EXP IN

  13. Calculate Level Progress – has the pawn obtained enough experience for a level?

  14. Level Up – Ding

Open the interface from the variables menu

  1. Tie all your variables to their respective node.

22e8a4d4e8ee24837dbb0bd00d4204be42524968.png

Functions

Give Experience

Set your EXP to the amount of EXP you just earned
Calculate your level progress
After calculating your experience, check to see if you are not max level and if you are above the required experience amount to level.
If you meet the conditions, level up.
If you have leveled, recheck level progress
Print a level up message
ff3f01870b1fa51209c52ae1a53a3cc3af91ebac.jpeg

Calculate level progress

Set your XP to current level

  1. This block serves to make sure that if you’ve leveled, your experience resets to 0 and you start again. If you bypass this node you’re experience becomes cumulative. Based on the EXP system you want, you may like that, though you’ll need to change how much you increment your levels.

Set how much exp you have gathered.
Set the required amount of experience needed for your next level
2b365cc35508ff7a79e6e89d8e43984b68d8f812.jpeg

Level Up
Level +1
Spawn an emitter to create an explosion – just the minimum required flair to get your attention
0a88087630b97078501f29714bcccf6925dd3731.png

Now all that’s left is to create a trigger to add experience to your pawn through the Give Experience function and you’re good to go.

Cheers,
Hakabane

PS: A really easy way to your system at work is to just create the below in your character BP
b30e06b7d6ae3818e48c0bf5917120ae3655d378.png

Awesome…thanks for putting this together…
http://media.giphy.com/media/rRGMu2D3QV2cU/giphy.gif

Very nice and indepth tutorial! But im stuck on something.

First off i followed everything but somehow my nodes look different from yours. (ill give a screenshot below)

Also i got to the part where you plug everything in to create the HUD and for some reason i cannot connect appends to Get Player Experience node am i doing something wrong.?

Here is a screenshot of my setup.

Edit: I tryed to skip ahead a bit so i could go back later if you find something wrong but i do not understand the Pawn part, Can you please explain that a bit more also?

In the Interface for “get player experience” you set up your nodes on the input side, not the output side. That is what’s causing everything to look awkward.

Here is a screen shot of my pawn’s event graph. There are already screen shots of the functions posted above. Not sure which part you are stuck on. Can you be a bit more specific?

I will be here most of today so I can help as much as needed.

thanks for dong this, and perhaps you want to also contribute to wiki as well?

btw, real challenge begins when you need to load different levels, ie. dungeons or go through anything to another world. since you’d have to migrate existing status.

I’m always happy to help when I can.

Keeping information when characters move from one area to another is something I know I have to deal with but for now I’m just sticking to the basics. I’m sure I will progress more though and find my way through any other issues.

Player Pawn (MyCharacter)
Enable the interface on this blueprint
Create the following variables:
EXP
XP to Current Level
XP Gathered for Next Level
XP Required for Next Level
Level (0)
Max Level (100)
EXP Increment (500)
Only EXP Increment is a float, the rest are integers.

Create the following function or macros, whichever you prefer to use.
Give Experience – We call this whenever the player should be given experience
Inputs (Type,Name)
Integer – EXP IN
Calculate Level Progress – has the pawn obtained enough experience for a level?
Level Up – Ding

Open the interface from the variables menu
Tie all your variables to their respective node.

This is the part i do not understand, after i create those where do i plug them in at.

You need to double click the section “Get Player Experience” above your variables. This should open up that interface and let you set the variables inside it.

Thanks i finally got everything setup, But for some reason i do not see the bar ingame what do i need to do to see it?

Post a screen shot of your hud BP, there are a couple things that could be making it not show up. do the numbers show up though?

I was able to use your last hud SS to see the issue. in the draw material simple node, set the screen H to 15

Ok i see the bar now but, I see no numbers and there is no part of the bar being highlighted. Ill Screenshot ingame aswell as Hud/controller.

HUD:

LevelUp:

45e11fe7c91bd79048d2b66e5f9f03cd7ae13d5a.png

LevelProgress:

4c594ab0aae30022a8d711a62a11a8d203a4cd28.png

GiveXP:

8476ada957e886f84cad61fc87d53aeff3d8f2fd.png

Material:

2f058ee2a105239093360921a1c95bdcc0d8d7cc.png

Ingame:

for the moment, can you set the text color in the “Draw Text” to red? you currently have it black and since your bar is black they wont show up.

once you do that, create an “event tick” in your pawn, give it a 1 second delay, then call “Get Player experience” and set the in integer to a random between 1-20.

Hopefully these should be all thats needed.

ooh wow thanks for sharing all this Hakabane!

Have you considered writing a wiki tutorial for this? that will give your tutorial the longest life span and ability to help others!

Rama

Once I get Fire through all this and we find all the spots that need to be reviewed I may, but I want to make sure people can get it done before I make a tutorial on the wiki

Ok i did that now i can see the text and stuff, but when i start my game it just auto levels, i do not see the xp bar or material or text moving, It says in the top left you have leveled and it plays the explosion emitter but nothing happens with the XP Bar.

In your EXP_BAR material editor, make sure that you name the two parameters at the very beginning the exact same as you have them in your hud graph. When these names don’t match up the exp bar does not act correctly.

They are the same name.

Edit:

Here is what it looks like when i play in editor, it shows the bar and everything but all that happens is the emitter and the text on the left of the screen the bar itself stays full and does not move nor does the text inside it.

In your pawn blueprint, do you have your xp increment variable set above 0?

Edit: Also, I broke my bar when setting that value to 0 and fixed it by going into the exp_bar and hitting apply and save after it finished rendering.

Yes it is set to 0, But i just noticed when i open my pawn and i click defaults do i have to change those values at all?