Announcement

Collapse
No announcement yet.

Experience System with working HUD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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: https://forums.epicgames.com/threads...erience-system. 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?lis...uO7N2Pmmw9pvhE

    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”
    Click image for larger version

Name:	EXP_BAR_Param Names.jpg
Views:	1
Size:	87.7 KB
ID:	1134411

    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)
    Click image for larger version

Name:	EXP_BAR_Colors.PNG
Views:	1
Size:	103.0 KB
ID:	1134412

    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

    Click image for larger version

Name:	HUD Const script.PNG
Views:	1
Size:	53.5 KB
ID:	1134413

    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.
    Click image for larger version

Name:	HUD - P1.PNG
Views:	1
Size:	89.9 KB
ID:	1134414

    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.
    Click image for larger version

Name:	HUD - P2.jpg
Views:	1
Size:	93.8 KB
ID:	1134415

    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.
    1. Create the following function or macros, whichever you prefer to use.
    2. Give Experience – We call this whenever the player should be given experience
    3. Inputs (Type,Name)
    4. Integer – EXP IN
    5. Calculate Level Progress – has the pawn obtained enough experience for a level?
    6. Level Up – Ding

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

    Click image for larger version

Name:	Interface.PNG
Views:	1
Size:	111.7 KB
ID:	1134416

    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
    Click image for larger version

Name:	Give Experience.jpg
Views:	1
Size:	61.5 KB
ID:	1134417

    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
    Click image for larger version

Name:	Calculate Progress.jpg
Views:	1
Size:	42.2 KB
ID:	1134418

    Level Up
    Level +1
    Spawn an emitter to create an explosion – just the minimum required flair to get your attention
    Click image for larger version

Name:	Level UP.PNG
Views:	1
Size:	106.9 KB
ID:	1134419

    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
    Click image for larger version

Name:	Give Me EXP NOW.PNG
Views:	1
Size:	48.8 KB
ID:	1134420
    Last edited by Hakabane; 05-02-2014, 11:11 AM.
    Movable Widgets

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

    Streams: www.Twitch.tv/BlinkTheory
    Patreon: www.Patreon.com/BlinkTheory

    Comment


      #3
      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.

      Click image for larger version

Name:	HUD.png
Views:	1
Size:	239.8 KB
ID:	1050395

      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?
      Last edited by Firezown; 05-02-2014, 06:33 AM.

      Comment


        #4
        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?
        Click image for larger version

Name:	Pawn.PNG
Views:	1
Size:	159.1 KB
ID:	1050406

        I will be here most of today so I can help as much as needed.
        Last edited by Hakabane; 05-02-2014, 11:21 AM.
        Movable Widgets

        Comment


          #5
          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.
          Unreal Engine 4 Game Framework diagram for relation of all major base object types
          Unreal Engine 4 Input Event diagram, scroll down to section Input Processing Procedural
          Resident Evil Classic Camera
          RPCs official document, Must Read
          Everything you should know about replication

          Comment


            #6
            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.
            Movable Widgets

            Comment


              #7
              Originally posted by Hakabane View Post
              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.

              Click image for larger version

Name:	Functions.png
Views:	1
Size:	31.1 KB
ID:	1050421

              Comment


                #8
                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.
                Movable Widgets

                Comment


                  #9
                  Originally posted by Hakabane View Post
                  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?

                  Comment


                    #10
                    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?
                    Movable Widgets

                    Comment


                      #11
                      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
                      Movable Widgets

                      Comment


                        #12
                        Originally posted by Hakabane View Post
                        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:

                        Click image for larger version

Name:	HUD.png
Views:	1
Size:	251.1 KB
ID:	1050423

                        LevelUp:

                        Click image for larger version

Name:	LevelUp.png
Views:	1
Size:	124.3 KB
ID:	1050424

                        LevelProgress:

                        Click image for larger version

Name:	LevelProgress.png
Views:	1
Size:	148.0 KB
ID:	1050425

                        GiveXP:

                        Click image for larger version

Name:	GiveXP.png
Views:	1
Size:	163.6 KB
ID:	1050426

                        Material:

                        Click image for larger version

Name:	Material.png
Views:	1
Size:	181.3 KB
ID:	1050427

                        Ingame:

                        Click image for larger version

Name:	Ingame.png
Views:	1
Size:	589.5 KB
ID:	1050428

                        Comment


                          #13
                          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.
                          Movable Widgets

                          Comment


                            #14
                            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!

                            https://wiki.unrealengine.com/Category:Tutorials

                            Rama
                            UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

                            ♥ Rama

                            Comment


                              #15
                              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
                              Movable Widgets

                              Comment

                              Working...
                              X