Alright, first thing to do, if you haven’t yet:
- Create a new Blueprint Class and use “PlayerState” as the parent!
- Open your new PlayerState Blueprint (I called it “BP_PlayerState”) and create a “CurrentScore” Integer Variable
- Also create the following Custom Event (see image)
– We use it to increment the Score by an incoming amount, so you can have different values for your gates (if needed)
Now we need the Widget, in which we display the score:
- Create a new Widget (mine is called “W_ScoreScreen” and open it up
- Add a “Text” where ever you want it, you can see my settings in the image below
- Now, select the Text and look at the right side into its Details
- At the top, give your Text a proper name. I called it “ScoreText”
- Also mark the boolean “Is Variable” with “true”
- Open the Widget Graph (Top right)
- You should see a grayed out “Event Construct”. If not, search for it in the right click menu
- Now do the following (see image)
– This will take care of grabbing the score from our PlayerState when we create and add the Widget to the screen
Now next is the GameState. This handles the general state of the game and will take care of ending our game:
- Create a new Blueprint Class and use “GameState” as the parent! (4.14 still GameState, not GameStateBase!)
- Create a Reference Variable for your Score Widget
- Create the following Custom Event (see image)
– We use it to end the Game and display the Widget
– We also make sure that we don’t create and add multiple widgets
Now we only need to actually have the two triggers.
Lets create the Score Adding one first.
- Create a new Blueprint Class of Actor (parent) and called it “BP_ScoreTrigger”
- Now add a Box Collision to it and call this one “Trigger”
– This overlaps “All” and is a “WorldDynamic” by default. Guess we can keep that
- Now click on it an create the “OnComponentBeginOverlap” event (see image)
- After clicking the green button, we automatically travel to the Event Graph and the new node
- Now add the following code to it:
This make sure the Actor is our Player (my class here is “BP_PlayerCharacter”, you need to use yours) and then gets the PlayerState
from it (which can be done from Character and PlayerController, so we get it from the Character directly) and cast it to our custom class.
Now call the add function and we are done.
Last thing is the end trigger, so go though the process of
That should be it. I haven’t tested it yet, but if you run into problems, just post them (: