Organise a game in rounds

Hello,

So I have this simple platform game where P1 and P2 run around and earn points. When score (p1 points int + p2 points int) == 500, I want the characters to be stopped in place (unpossess?) / disappear (destroy → respawn). The score shall remain unchanged:

Score: 0 → 500 1st round → 1000 2nd round → 1500 3rd round → 2000 4th round.

However, at the end of the 1st round, as I was saying the players should be stopped in place / disappear and a ‘Round 2!’ text and preferably a ‘3, 2, 1, go!’ countdown to appear on screen. Then the game plays again up to the 3rd round and the same happens until the end.

How do I add text like that to the view port between rounds?

At the moment I have this in the GameController BP and when score > 30, P2 gains 500 points and a print so I know it works.

Do I keep going with presumably, whatever add to viewport → something → round 3 → something else → round 4 after the condition checks (event tick node)?

*Can I organise each round independently? as in make round 2 a custom event and tie the text to it and the condition then round 3 as another custom event and so on, then just call them consecutively in ‘Event tick’? *

Any help is greatly appreciated. Thank you!

the method you mention should work however i prefer to make things a bit more modular (reusable = less work) and i like to make things stateful (not rely on tick). so with that in mind below is one example of how your script could be done.

the first picture shows the game mode which takes care of most things. here we begin with a custom event AddScore which you can call any time you want to add to the total score. once the score is add we then call a event Check score to see if we passed the round threshold. the check score function is only called when score is added so it will perform better than checking the score on tick. the score check is pretty simple we get the current round number then use that as a index for the select node which stores the thresholds. then we ask is the current score total greater than or equal to the threshold, if true then we progress on. we then increment the round and call the next round event. the NextRound event is where you would handle destroying your actors as you mentioned and respawning them, then you would create the countdown widget.

this brings us to picture 2 which is the countdown widget. this one may seem a little confusing but at its core its just a basic loop that runs once per second. for this widget is just created a text component and bound its value to the variable display text. when the widget is created (event construct) we get the current game mode and cast it to the one we were just working in (in my case GM_ScoreGM). now the rest of the script will be run both on construct and on the custom event change text. next we set the display text variable (the text that will be shown). now what the text is set to is based on another select node. for the first option we get the round number from the game mode then add one to compensate for the round being zero based, then we use an append node to combine "round " and then the round number (the space after round is important). for the rest of the options we just use the count down numbers. also note here the index variable which we will be incrementing just after the set display text node. after the increment we need a delay so that the text is displayed for a specified time. then we run a check to see if the index is less than the number of options we are using, if it is less we know we need to loop again so we call ChangeText, if the index is greater than the options then we know we are done and can safely destroy the widget.

you could modify the widget and use images if you wanted to as well and use a similar process. hope that helps a bit.

This is hands down the best way to go

Hey Thompson,

I’d like to thank you very much for being prompt and taking your time to provide me with such an in-depth answer. I have closely followed your instructions and it works! … with one or two exceptions - mostly due to my lack of knowledge as I am a beginner.

So the rounds work as established. However, my problem now is that I’ve literally no idea how am I supposed to destroy the actors and re-spawn them in a proper way. You see, I have 2 Target Points in place and the characters spawn there when the game starts. One character picks up a ball item (overlap → attach to actor → grant points etc.) but when a new round starts the item remains stuck to the character, granting him points per second (as intended).

How do I ‘reposition’ the item at the end of the round, so that it’s not attached to the actor anymore, granting him points?

*The spawning system is making me rather confused, I followed a guide and although I did get the main idea, I have no clue how to re-use that one in this case, to destroy and re-spawn my chars at the end of a round. How about just hiding the blueprint maybe? instead of having to destroy them. That way the functionality would see no hinder. *

I am sorry for the torrent of questions. No offence taken if you choose not to guide me anymore. Thank you again, you’ve helped me enormously!

(I have attached the blueprint for the actor spawning to the TP’s - targetpoints)

when a new round starts the item remains stuck to the character, granting him points per second (as intended).
How do I ‘reposition’ the item at the end of the round, so that it’s not attached to the actor anymore, granting him points?

these two points seem counter to each other so im a bit confused as to what you want to happen. i actually dont really understand your game much at all actually, is it about points or distance and there doesnt seem like theres anyway to lose (this isnt pertinent to the question just a observation).

in any event, at the end of the round do you want the ball to drop where it is, or respawn at its initial location, or remain on a player? also is there any information contained in your characters that needs to persist between rounds, this will determine if you want to jsut set the location of the player of spawn new ones, probably best to just move them.

There are 2 players running around the platforms. There is one item that a player can pick up and needs to run from the other player - like catch!. While a player is in possession of the item, they get points / second. The other player can steal the item by catching the player in possession of the item.

I want the players to be reset at the initial target points if that is possible, and the item repositioned. Because when the round ends I can still move and the item is still attached to the player, which means he gets points per second still.

I want the players to be reset and froze until the text ticks ‘Go!’. The item should be detached from the player and repositioned.

Edit: I have tried teleporting the players back to the Target Points but I couldn’t get to reference those points in the GameMode bp. If I could reference them I think that’d work and all I’d have to sort out is the item repositioning. Maybe if I try setting the location manually.

alright i think i created your entire system and learned a little myself along the way. note that this is just one method and there are many others and this could be improved upon im sure. for this approach i relied on moving actors instead of spawning new ones and i used event dispatchers because well i hadnt really in the past.

ok we begin in the gamemode where ive added on to what was shown previously. this will also be the central blueprint that the others work from. first thing i did was to get a reference to all the characters in the level on begin play then save them in a array for use later. next i created the event dispatcher (yellow arrow bottom left). i then called the event dispatcher (newRound) at the end of the next round script (bad naming i know). the last thing to do in the game mode is to create a CountdownFinished event which we will be using to allow the players to move again once the new round starts. the countdownfinished event just gets the array of characters we stored earlier then runs them through a loop setting the movement mode for each one.

next comes the widget which has two minor changes. first i saved a reference to the gamemode to a variable to make things neater. then near the end of the script i called the countdown finished event from the game mode.

continuing on to the character i created a script which saves the starting transform, binds the NewRound event, sets the actors transform, and disables character movement. basically on begin play we set the variable for the starting transform and bind the event. binding the event means that when the GM calls the event the CharNewRound will be executed, the actor is listening for the call.

im out of space here so continued below.

the last thing to cover is the ball bp. the begin play here is much like the character’s setting a initial location variable then binding to the newRound dispatcher. the difference here lies in the bound event where we still set the actor location but before that we have to detach the ball from whatever actor its currently on. the other section of the script is a basic way of doing the switching possession of the ball. i used begin actor overlap, then casted to character so only other characters can take the ball, then attach to component to attach the ball to the character (i used a socket here to attach the ball to the characters hand). the rest including the branch, the set nodes, and the delay are there to control how quickly the ball can be transferred, basically so it cant go back and forth super quick (limited it to every 0.5 seconds).

thats basically everything you were looking to do. i didnt include the adding score part since im sure you can figure out how to do that with a timer and setting a reference to the player holding the ball. if you need more info on event dispatchers i would watch the video linked below. also i made this and tested with a third person project (4.17), some things may be different for you since your working in 2d. anyway that should be all the basics of what youll need to do. should be enough to get you started in the right direction at least.

Hello again,

I cannot thank you enough for the gigantic amount of help you’ve offered me. The game is now working as intended and I can finally move on to adding obstacle events and such! Tell me, why do you do this? I am pretty sure you have a job in programming and you’re seeing blueprints daily… and yet, you dedicate your time to helping complete strangers; and to what extent! This last post was crazy in depth!

I did use parts of your blueprints and combined them with what I had already in place and everything works flawlessly now. I am at the moment thinking of a way to end the game and display a results screen after the 4th round ends, but that should just be a matter of ‘if score == 400 add widget etc.’.

To me this all felt like a whole new level of blueprinting (as a level 6 games design student) and then you called it ‘basics’. Fair point man, I hope one day I’ll be as good as you. Cheers for everything!

And for the video!

haha thats pretty funny i actually work in the dental industry and am a hobbiest when it comes to UE4. i actually taught myself how to use ue4 off and on over the past 2ish years.

as for why i do answehub stuff well its good to help people right and its a good way to learn UE4 too. think about it the best way to learn is to teach right. combine that with the crazy things people here come up with and trying to explain in the most basic way, you end up reenforcing the basics quite a bit. makes you come up with interesting solutions to things too.

i have no idea what a level 6 design student is but in the grand scheme of programming im not that advanced. i look at the blueprints of someone like Ian Shadden (think thats his name) and i cant begin to follow somethings (his A* in blueprint is amazing - see turnbased example).

You made your point actually; you do actually learn a lot yourself by teaching others. I’d like to do this as well maybe once i get the minimum of knowledge in blueprinting, scripting and such. However this is not my domain, I’m focusing on 3D animation in general. I am surprised on how much you were able to learn by teaching others. Props to you!
(Level 6 is regarded to as the last year of university in chase of a Bachelor’s.)

I’ve seen some of Ian’s videos. I have no idea what is going on for the most part. Guy’s a genius.

Do you happen to have experience with particle systems by any chance?