Item Collection


I’m currently working on a small game for class where you play as a dog and you have to find all eight tennis balls lying around the level before time runs out, or else the game ends.

The only things I’m having trouble figuring out is making it so that whenever the dog moves over a tennis ball and it vanishes (I already got that part down by putting a destroy actor node), it’s added to it’s collection and when you walk over eight in total, you get a “You win” screen.

I’m also using this timer blueprint for my game, but I can’t seem to figure out how to make the game end/take you to a game over screen once the timer reaches zero.

Any help is appreciated, thank you.

Depends on how you implement score screen.

Easiest would be creating it in 3d at some map location.
Then setting player controller (or pawn) location to that place.
And you need to change controls to stop people from running in score screen.

You can always create SECOND player pawn and controller.
Then you unposses current controller and posses one at score screen.

How are you doing the ball interaction?
Are you using an overlap event?
If yes, you can just cast to the player character and increment its ball count.

Or you can give the player character a variable that contains a reference to your score display widget.
The ball then reacts to the overlap event by calling a function on the widget - for that, it uses the “other actor” node on the overlap event to get a reference to the player character, which in turn allows you to cast to the player character and get the reference to the widget.
That function would then do two things: Increment the ball counter and check if the counter has reached 8.
If the check returns true, you invoke a “you win” widget.

To get a “Game Over” screen, you need a widget and create a custom event for it. This event is then bound to an event dispatcher.
Your timer implements the dispatcher and calls it when the loss condition is reached, which causes the custom event on the widget to fire.
That custom event should be used to make the Game Over screen visible.

I seriously hope the game has more elements than just collecting balls, and that you simply failed to find a solution for these last two things after doing research. Otherwise I pity your teacher.

I’ve got the timer bit figured out since I found a video so no need to worry about that.

Anyway, I’ve managed to make it so that when the character (dog) walks over a tennis ball, the collectible vanishes and the Win widget comes up. The problem is that it only comes up when I collect one tennis ball when I just want it to show after getting eight.

Here’s my blueprint for my character (dog)



How about not making assumptions. My teacher isn’t expecting us to make a super in depth game since this is a beginner class and he approved my idea. Believe me, I’d love to do more but the time frame we have and my skill level (I’m very new to all this) doesn’t allow me to make it better than I wanted. Perhaps in my free time, I will do more.

Why not add a Branch node comparing Items Collected to 8 and on the True output, create the widget?

At that stage, you are basically finished.

This is a good reference:

Just make a branch. The boolean that you want can be created by using a logic node.
This is what you need:

It allows you to compare two integers to generate a boolean (true or false) value from it.
Just put the branch in front of the “create widget” note and make it compare your “items collected” to the target number.
Your program is currently structured such that it will check the condition every time an item is collected, which is exactly what you want.

Yeah, sorry for overreacting, but I tend to get pretty annoyed at “please do my homework” posts. They often result in people who start whining when tests come around.