Nothing after Print String will do anything because there’s no execution wire. You should be able to connect white from the first Set node to the Print String.
I’m no expert on widgets. But if you just want the score printed out to the screen then you won’t need the Score Widget. or anything after it. Also note that the second Set node will always set the score to 0, which I doubt you want to do?
Thanks for that Kev, it’s very much appreciated if I connect the first set node to the print string will that output to screen correctly mate?
I definitely don’t want the result to always be zero, I’ve got a number of volume triggers placed around my map as gates I just want something that pops up on the screen (preferably when the game ends) that shows how many times the player has used a gate.
Thank you so much for that Diat I really appreciate it, additionally I’ve seen you’ve got time showing in your fps template, can I ask how you managed to create that as it’s something else I’m trying to create.
A question from me now: My assumption is that we’d want to include a cast in the Your Overlapped Actor graph. Is that not necessary? Else won’t we be counting all overlaps, not just those between player and trigger volume? Thanks in advance if anyone can explain that one.
Here it is:
Started by Begin Play connected to the Gate [Enter]…
Hi Kev!
You don’t need Cast nodes in Your Overlapped Actor because you get the variable you want to display (“Score” Int variable) from your widget blueprint with Get All Actors of Class —> GET —> Variable.
Overlap Only Pawn is a good preset for the actor we want overlap, because only pawn actors can overlap it…all other actors will be ignored or blocked. If you have many Pawn Actors but you want overlap the actor only with your playable character, you can create a Custom Collision Object/Preset (with the same Collision Pawn settings) and assign it to the non-playable actors: Add a Custom Object Type to Your Project in Unreal Engine | Unreal Engine 5.3 Documentation
Just so you know, you should avoid “GetAllActorsOfClass” if possible. It’s not a good coding habit!
The way this can be solved here, is the following:
In the UMG Score thing, create a variable of type: “YourOverlappedActor REFERENCE”. This will be empty by default, as you need to fill it with an
instance of the class. You currently get that instance with the AllActors stuff.
Click on the Variable again and go to its options. Select “Editable” and “ExposeOnSpawn”. Save and compile.
Head back to the “YourOverlappedActor” Blueprint. Check out the “Create Widget” node. It should now feature a pin of your variable. (If the UMG Score Widget is selected to be spawned!)
Drag it out into an empty spot and search for “Self”, which is a reference to the Actor your are working in.
Then you can use that variable in the Widget (:
EDIT: Also, why do you create the Widget EVERY TIME the thing gets an overlap event?
Create the Widget once on BeginPlay of your Controller or what ever. Save it to a variable and just leave it rest there.
If you want to hide/show it, you can always just get your controller, cast it to your custom class and access the Widget variable.
Hey @eXi, many thanks for your contribution…that was just an example.
I usually create the widget with Begin Play, SET a variable (variable type is = widget) and when I want to add the widget to Viewport I use this variable.
Is this the best method in terms of performance?
Yeah, it’s fine. Just remember that you answer questions here. Even if YOU do it otherwise normally, you teach people to do it wrong right here.
If you provide examples, make sure they are logical correct and explain why you did what you did.
I know that OP had the create widget in the overlap already. Would’ve been better to show him a general correct way (:
Thank you guys for all your help much appreciated, I’ll probably still need help putting it together and getting it to work though! @eXi can you please show me what you mean in terms of how the bp should look as I’m having difficulty following what you mean exactly.
Ok guys slight problem, I have followed the examples above but my count always starts from 2 instead of 1.
I’ve ultimately gone with the most basic setup without using widgets and I’m trialling with only two trigger volumes (gates) that each time the player goes through each should increment the count by 1.
I also only want to print the contents of the score variable yo screen when the game ends?
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 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
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
Creating a new Actor Blueprint Class (mine is called “BP_EndTrigger”)
Adding a Box Collision
Adding it’s “OnComponentBeinOverlap” event again (same as before)