DEV Community

AruPV
AruPV

Posted on

Making my first game with Unreal Engine 5!

Hey all!

It's been a little while since I posted here (it was a hectic summer). I'm working on a game now! I would describe it as a first person, sandwich-making, single-player overcooked clone.

The general gameplay loop is quite simple. Clients come in and order what sandwich they want, and you just go have to build it fast for them.

Screenshot of my game, it shows a green goblin acting as a costumer in front of a floating dish. Some ingredients can be seen to the side on a table. It is set in the default "Blank" space of unreal engine 5

Let me guide you through my code right now and show you how it all works!

Player

The player character is relatively simple. It holds the movement events, an event on left click that interacting with things in its environment, and a couple of blueprints for both adding ingredients to its hand and putting them down.

On left click event graph

The left click was one of the first things I implemented and I was really proud of it when I made it. This is how the player grabs and places ingredients, but also how the player confirms that an order is ready to be delivered to the costumer. It fist line traces from the camera forward and gets its hit result, then it checks to see if the player is within that element's collision box. If it does, then it sends a message through an interface "PlayerInteractionInterface" that tells the item the character has interacted with it.

An Add to hand event and an empty hand event

The other two interesting events in this blueprint are implemented from two different interfaces. AddToHand is a message sent from the ingredients blueprint that checks if the character is holding something, and if they aren't sets the character's "OnHandString" to the name of the ingredient, adds a mesh to "OnHandMesh" and sets the "HandFull?" boolean to true. EmptyHand simply clears every one of these variables I just mentioned and is called by the trash can blueprint.

Ingredients

Probably my simplest blueprint at the moment. It holds a couple of variable: It's own static mesh, a mesh that shows when held on the players hand, the name of the ingredient, and whether or not the ingredient is a kind of bread.

Blueprint for the ingredients class

It only shows one event, which is part of an interface with the player blueprint. When the player interacts with the ingredient on the table, the ingredient will send its relevant data to the player (ingredient name and on-hand mesh).

Sandwich

This blueprint might need a bit of a redesign later, but as of right now it is the plate onto which the player builds the sandwich, the object a client sends the order information to, and the one in charge for comparing that both the sandwich made by the player and the one ordered by the client match

Blueprint for the Sandwich showing an "add to sandwich" event and a "player interaction" event

I was really struggling at first to figure out how to not have all the different meshes for each of the ingredients of the sandwich not just appear in the same space (or float at odd intervals from one another), but I think I figured out an okay solution!

When a character send a message to the sandwich that it has interacted with it, the sandwich calls its own "AddToSandwich" event and messages the character to empty its hand. AddToSandwich checks to see if the character is holding an item, and if it is, it adds the string of the ingredient it to an array called "BuiltSandwich." It then creates in itself a new static mesh at the transform "NextMeshPosition," which has default values of 0 for all axis, and that uses the mesh from the ingredient on the player's hand. Finally, it changes the Z value of NextMeshPosition to itself plus whatever the Z value of the new mesh is.

Add client to queue and submit sandwiches events

Next couple of events are the "AddClientToQueue" and "SubmitSandwich." The first one just adds a reference of any new client that is assigned to that sandwich to an array that holds them called "ClientQueue," and the second compares the built sandwich array to the ordered sandwich.

The comparison is handled by a "CompareSandwiches" event (don't really think I needed another event just for this but oh well!).

Client!

This is I think my most complicated blueprint right now.

Constructor for a Client

When initialized, a client runs three different events, "Initialize Bread Fillings," "New Order," and "Attach to Sandwich." The last thing it does is it toggles the visibility of its speech bubble (how you know what the order is) to invisible.

Get all breads and filling event

The first event, the "Initialize Bread Fillings" grabs all the different ingredients in the scene and adds them to an array. It puts all ingredients that have a the "isBread?" boolean true to the breads array, and adds all the ingredients that do not to the fillings array.

New Order Event

After that, the New Order event is triggered. This picks a random number (between 1 and 4 at the moment) and runs the "GetRandomBread" function to get a bread to be used in the sandwich, adds this bread to the ClientOrder array, and then runs the "GetRandomFilling" function for as many times as the random number said to do, adding each to the array. At the end, it adds another slice of bread to the ClientOrder array.

"Attach to Sandwich" Event

Finally, the client will "attach" itself to a sandwich with the "Attach to Sandwich" Event. This event simply looks at all the sandwiches in the scene, picks one at random, saves a reference to it and sends a message to this sandwich to add the client to the queue.

At Game Start Event

Finally, when the game starts for the client, the game will grab a reference to a material in its mesh (this will be used to change the color of the client with time), moves itself to the sandwich, updates the speech bubble to have the correct order, and on arriving at the check-out will change the visibility of the bubble to visible and make the client more impatient

Receiving message from sandwich event

Once the player sends either an incorrect or correct order, the following code runs which calculates the score and pushes it to the game mode

calculate score

The calculation of the score is quite simple. There is a minimum score that any correct order will get, and there is a bonus score that the player can get depending on how fast they make the sandwich

Patience Clock

Patience and time until the client storms out the door is handled by this event, which is also in charge of making the client appear more red as the time to it being "pissed off" decreases (right now, the client does nothing when pissed off but will do in the future).

This post is getting a bit long!

It's been really eye opening seeing how much goes into making even this simple of a game. TBH Maybe I'm biting off a bit more than I can chew right now, but I am having a blast so I don't really care too much. I haven't shown you all everything in the game, but I think this post is getting rather long already. I will make shorter posts in the future talking about each feature as I add it!

Thank you for following me along this journey!

Aru

Top comments (1)

Collapse
 
eduardopoleo profile image
Eduardo Poleo

Amazing! keep it up!