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.
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)
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
Event Graph in UMG
Calling UMG for my Ammo
Calling UMG on Game Start
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.
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.
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).
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.
Thanx << but are this work in multiplayer system ?
Is is didn’t work in multiplayer
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.
Hey everyone, just wanted to share a plugin which adds a comprehensive score system to your game. And you just need to add a Score Component in PlayerState. Check it out and let me know what you think!