Announcement

Collapse
No announcement yet.

setting up a basic score system

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

    setting up a basic score system

    I have working health, energy, and ammo set up on a basic level right now. However, I'm trying to figure out a way to set up a score system with my UMG.

    I can't seem to figure out how to call my UMG in the event graph to get my score to update. Let's say I have a destructible mesh. Every time my projectile hits it, I'd like to have my score get updated. Super easy right? lol...

    Can someone help me set this up? I can't seem to get it to work because I only know how to call "get player pawn" in UMG event graph. However, with the object I want, it's not a player pawn.

    I just want to have my score go up when my projectiles are hitting the object.

    #2
    First good thing to know is: Is this a multiplayer game?

    I would do it the following way:

    Each Player, even your SinglePlayer "Player", has a so called "PlayerState". You can access the PlayerState
    with your PlayerController (So you can get the PlayerController and from it the PlayerState inside of your
    UMG Widgets). The PlayerState class is used to save the.. Player's State. So what does this mean?

    There are 3 basic variables already implemented. "Ping" (Network relevant), "PlayerName" and "Score".
    Although you can't set these in Blueprints, you can create your own PlayerState BP Class and just add
    your own Score variable.

    Now since you can access this PlayerState through the PlayerController, you can just create an Event to
    update your own Score variable there. Then you call the Event when you hit the object by getting the
    PlayerController and the PlayerState. Normally you give the projectile a reference to your Player. That
    way you know who shot. You can get the Controller from a possessed Pawn and from that the PlayerState.
    If you have a SinglePlayer game, then you can just use "GetPlayerController0".

    And in your Widget, you do the same, get the Controller, get the PlayerState from it, cast it to your custom PlayerState
    and get the Variable to display it (:

    (NOTE: The PlayerState Class can't be set in the "Maps and Nodes" Settings. You need to open your GameMode Blueprint
    and check the Class Defaults button at the top bar and add the PlayerState on the right side in the settings)
    Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

    My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
    (Including 100+ Pages Multiplayer Network Compendium to get you started.)

    Comment


      #3
      So it's a single player game only. Unfortunately though for me, I'm having a hard time understanding just how to do what you said..

      Here's what I do have.

      UMG Designer window
      Click image for larger version

Name:	7sGrD6Q.png
Views:	1
Size:	211.8 KB
ID:	1083462

      Event Graph in UMG
      Click image for larger version

Name:	XupvPYW.png
Views:	1
Size:	108.0 KB
ID:	1083463

      Calling UMG for my Ammo
      Click image for larger version

Name:	nfOsCpk.png
Views:	1
Size:	109.0 KB
ID:	1083464

      Calling UMG on Game Start
      Click image for larger version

Name:	adXJSMo.png
Views:	1
Size:	274.1 KB
ID:	1083465

      Does it help to know that my ship you see casted to is a controllable pawn? not a player controller? Does that change the way this is going to work out? Sorry I should've been more specific.

      This is how I'm trying to update my score on the object I'm trying to destroy. This is how I'd like my points to get updated. I'm just not sure how to call it from the UMG. It's a blueprint created from a destructible mesh.
      Click image for larger version

Name:	FkbHWqc.png
Views:	1
Size:	73.8 KB
ID:	1083466

      Comment


        #4
        Where is the Score Variable located?
        Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

        My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
        (Including 100+ Pages Multiplayer Network Compendium to get you started.)

        Comment


          #5
          Originally posted by eXi View Post
          Where is the Score Variable located?

          It's on the object I'm trying to destroy. The last pic you see is the destructible mesh blueprint.

          Comment


            #6
            Originally posted by Illuzioun View Post
            It's on the object I'm trying to destroy. The last pic you see is the destructible mesh blueprint.
            Ah, that's the wrong place. Since you're going to destroy it, the score value will vanish.

            Save it in the PlayerState BP. Create one like this:



            Then add it to your current GameMode as the default PlayerState class:



            Inside of the PlayerState Blueprint, create your Score variable. There is already one from Epic, so name it a bit different!

            Now, inside of your Actor you want to destroy, do this:



            And since you already know how to bind a value to your Widget Text, do this for the binding:



            Normally you should make sure that every exec (so also the cast fail and IsNotValid one) reach the ReturnNode. Otherwise you could
            get crashs. I do this by adding a Local Variable for the return value and set it to a empty or a default value if the casts etc fail and
            otherwise to the value i wanted to return (the score at this point).
            Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

            My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
            (Including 100+ Pages Multiplayer Network Compendium to get you started.)

            Comment


              #7
              eXi, You're amazing. Thank you soo much for walking me through that!! I'm extremely grateful! Appreciate the time you took to take pictures and make this for me!!

              Comment


                #8
                Originally posted by Illuzioun View Post
                eXi, You're amazing. Thank you soo much for walking me through that!! I'm extremely grateful! Appreciate the time you took to take pictures and make this for me!!
                (: You're welcome. If you have any questions, please tell me.
                Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

                My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
                (Including 100+ Pages Multiplayer Network Compendium to get you started.)

                Comment


                  #9
                  Thanx << but are this work in multiplayer system ?

                  Comment


                    #10
                    Is is didn't work in multiplayer

                    Comment


                      #11
                      This thread is super old, but to chime in in case more people stumble on it through Google: my understanding is that this should work for multiplayer as long as there's an instance of the custom Player State blueprint per player, to keep a separate tally of each player's score.

                      Comment

                      Working...
                      X