This is for a VR game.
I have 24 “pins” placed on stands that the player can knock over by throwing balls against them. I want a scoring system with several scoring classes (pins further away have higher scoring value) and ultimately have the score printed to a widget placed somewhere in the world.
Knocking the StaticMeshActors into or out of a TriggerBox would be the way to go (can get it to print a string), but how do I set this whole system up and create the different scoring classes?
lots of ways. You could have an array of structs which are a float Distance and an integer Points and loop through it using the Greater Than operator against the distance between the pin and the player and apply the Points to the player’s score when it reaches the array entry where the pin distance is greater than the Distance part of the struct at that array index, and then break the loop. This works if the array is arranged im ascending order of Distance.
You could also just apply the exact distance itself to the score instead of breaking it up into distance brackets.
Distance is the length of player location minus pin location.
There are other ways too but i think one of those two would work.
Thanks guys, I used the integer variable with instance editable enabled and manually entered the score value for the pins.
I created a Widget Blueprint (“Scoreboard”) with two Texts (“Score:” and “0”) but I’m unsure how to go about sending information to that widget to update the “0” and displaying it in the world.
You could just create Pin BP with an integer variable that is instance editable and manually enter the score you want for pins further away if you are hand placing the pins. If they are spawning at random locations away from the player then you could have a function that uses a “get distance to” node and use that value as mightyenigma said to set up some logic for how you are going to determine when the value should increase based on distance. As for the widget stuff, you would need to create a widget, prob in player character as this would be the most straightforward place, then have a text variable in the widget that you grab a reference to from the player character or Pin BP and have it update itself based on the changing player score or something like that.
What you need to do is create the widget in the character BP, from the character BP every time a pin is knocked over have it add points to a variable like “player score”. When player score is updated, access the widget in the character BP and tell it to update the "text’ in the widget from 0 to whatever the player score is. I have a tutorial that goes over some of this stuff. It is not exactly what you are doing but you should be able to get the idea of how to access widget data from other locations.
Hope this helps, if something is confusing let me know. (You would only need 1 widget FYI and create it in the player character, for the other widget I used, that would basically be your Pin BP)
Isn’t it more logical to place the score counter somewhere in the 3D world, like an actual scoreboard? Remember, this is a virtual reality only game. Also I have no idea how to actually tell anything to update the score once a pin is entering or leaving the TriggerBox…
Not sure how the VR stuff works but either way you’re not creating a “real” score board. So if by “in the 3D.world” you mean a game actor like your pins as opposed to a widget displayed on the player camera then sure. It’s the same general idea, now you just need to crate a text variable in your 3D cube or something and update that when pins get knocked over.
I guess way I’m trying to say is, a widget is a widget is a widget haha whether it’s just in front of the player camera like a HUD or drawn in front of a 3D object in the “world” it’s still a 2D asset. The only difference between a HUD and a floating text widget is where it’s created and how you reference it. So if you create a score board widget and a 3D model to go with it, then create an actor blueprint, add your 3D model as a component and then place the widget into the same actor you’d have a score board widget “in the world”. To change the value of the widget text you’d have to reference the score board actor. Get the widget component, get the user widget object out of that component, cast it to the score board widget class, and from the cast output pin get the text that represents the score. Then modify accordingly.
I meant a 3D object with a text floating in front of it, which updates based on amount of points scored. I suppose this is it?
I already have my scene setup and blueprints for each unique pin value/color. I just don’t know which nodes to use and the video tutorial doesn’t make much sense to me considering my scene and VR setup. I know what I want, just don’t know how to do it with what nodes.
Thanks! So far I think this is the logic I’m looking for? Now how do I get it to start counting the score once a pin has entered the TriggerBox that’s in my level? I already have a variable Points Value (integer) in place on the pin blueprint and assigned a number to it.
I’m not seeing the “000” from the widget in the editor yet, is that normal?
Go to the scoreboard BP viewport, you should be able to see the “000” floating in there somewhere, if you don’t then you have a problem. Most likely the size of the widget is too small or it is not in view, but you should be able to move it around and resize it until it is in the right place. Also, widgets are 2D so you can only see them from the front or back depending on how everything is oriented. So if you click your widget in the scoreboard viewport and use the rotate tool, spin it around 90-180 degrees you should see it at some point along that rotation path. Then you will know which way it needs to face to be visible to the player. As for getting the “Score” to change when a Pin crosses the trigger box, oddly enough I made someone else a tutorial for how to get a timer to stop when a player enters a trigger box, so the set-up should be identical to what you need to do, the only modification you would need is instead of “on trigger overlap with player” you would have “on trigger overlap with pin”. So you would cast to your Pin BP not the player, after that event occurs, get the “score value” integer from that PIN and add it to wherever you keep track of total score and then use that value to update the timer variable in the video which in your case would be the “000” widget. And to get to that widget reference, you would need to select your Scoreboard actor then open the level BP and right click in the event graph and search for create reference to selected object. Now that you have the scoreboard actor, get the widget out of there and go through the process I described in the prior comment for getting the widget object out of it. Hopefully that solves all your issues, if not let me know where you are stuck.
You’re right, I had to scale the font and widget size, I can see it now so that’s all working correctly.
What I don’t understand is:
- Which Object to add to the Cast to 1punt002_blueprint (one of my 1 point value pins)
- How I can add all my pins to this setup so they will all count score (maybe I’ll understand once I get this working with one pin first)
I feel like I’m getting pretty close now but probably did something idiotic, thanks so far!
You’re getting the reference from the overlap event you don’t need any casting, and you can just select the target eye blueprint for the equal node, you don’t need a reference variable there is what I’m saying. I needed it because there was no way for me to make the references without a cast
You need a set-up more like this. And my bad, you do need to either cast OR have a reference variable for that “=” node.
Thanks! My cast to PlayerScore_BP node gives a warning though, it’s probably VR related but I’m not sure what to use instead of GetPlayerController.
And I can not get the node that is your “Set Total Score (player)”, I assume it should be my “Score” from PlayerScore_BP. I also can not get any “Score” node from the Player Ref, not a green one like yours anyway.
Those are my variables, you need the corresponding ones from your blueprint. And player score BP is the scoreboard right? So get controller or player pawn or character won’t work. You need something like get all actors of class. Or if this is in the level BP select the scoreboard actor in the editor, open the level BP, right click in the event graph and search for “create reference to selected actor” then you can use that reference to modify variables
Just looked at your set up… so that’s your widget and you already created it in the level blueprint and stored it as a variable. So you don’t need that entire part where you cast to it at all. Just delete it. You only need pin 2 from the sequence in the level. If you look at my screen shots you’ll see I’m casting to the player character because that’s where I stored the points variable. Then I create a widget. You’re doing everything in the widget so you don’t need the cast node I used. You already have all the data you need from within your widget.
That cleared things up a little and it makes sense to me. You’re right, PlayerScore_BP is my widget (named “score”) and it’s stored as variable (named “Player Score Ref”) in the level blueprint.
But I just can not get the part into my blueprint that I’ve circled in red in your example. You say I have all the data I need and my setup all seems logical to me, but this last part I just can’t get working. Namely your Set Total Score node, am I missing some variable somewhere that I didn’t create? I know I’m being thick 