UnrealBasicsAssignment
UnrealBasicsAssignment
Objective / Goals
1. To explore Unreal Engine
2. See how Arrays are handled in Unreal and how to loop through them
3. Learn ways to print information to the screen
4. Learn how to add input
5. Create a custom class to handle items
Materials Needed
● Unreal Engine 5.0.X
Additional Resources
● Blueprints Documentation
● Unreal Learning (Must Sign In First) - Your First Hour With Unreal
● Unreal Learning (Must Sign In First) - Unreal Editor Fundamentals
● Unreal Learning (Must Sign In First) - Blueprints - Essential Concepts
Instructions
Make sure you read through the instructions. If you only follow the images in this document to make
your code you will miss out on some vital steps you need to take in order to complete the assignment
properly. It will take some time to get through this assignment so plan accordingly.
For this assignment you will be exploring Unreal Engine, adding your first actor, adding variables, using
the text render component, adding input, and using arrays. These are all necessary first steps in game
development and will be some of the tasks that you will probably be doing most often.
Getting Started
If this file is not associated with your Unreal Engine install you will need to open it with Unreal Engine. To
do this right click the project file and select Open With. If Unreal Engine shows up in the list select that.
Otherwise you will have to choose another app. Select this option and select more apps if you do not see
Unreal Engine as one of the choices. At the bottom of the list you will see Look for another App on this PC.
Select that and you should be in your program files folder. Navigate to Epic Games-> Current Version of
the engine you have downloaded(UE_5.0) -> Engine -> Binaries -> Win64-> UE5Editor. Then select Open.
Dock the Tab to the rest of the project and it will be easier to work with this way. Click and drag it. In the
Components tab in the top left corner of the screen; click the green Add Component button. Add a
sphere component and hit enter. Compile.
Note: Any time something is added to a blueprint Compile. If you add Variables, Components,
Functions, or if you make changes to the details panel. Compile!
Let us make Unreal Engine work for us. Next to the compile button there is a button that looks like three
vertical dots. Click the button and hover over Save on Compile. Select On Success Only. This will ensure
that Unreal Engine saves that blueprint if we compile successfully. You will need to do this for every new
project you create.
Next select the sphere component in the Components tab. Once selected the details panel will
populate with content related to the sphere. Scroll down to the collision category. Select the drop down
next to Collision Preset. Change the collision settings from block all dynamic to overlap all.
Adding a Variable
Let’s add a variable named “Cost” to the BP_Item blueprint. Navigate to the My Blueprint tab in the
bottom left hand corner of the blueprint editor window. Scroll down to the Variables section and click on
the +(plus) symbol. This will automatically add a variable of the last variable type selected. We will need
to change the type. Over in the details panel with the variable selected click on the variable type drop
down to select Float. We are using a float because when dealing with prices; they have a decimal place
and floats are a variable type that offers decimal precision. Make sure to compile. After adding a variable
we need to compile because Unreal Engine has to create that variable in order for you to change its
default value. However, we are going to leave the default value of Cost at 0.0(when using the details
panel to set variables this is known as compile time). We will modify it in the begin play event(setting
variables during the execution of code is known as runtime).
Navigate to the Event Graph. If you can’t find the event graph tab you can double click the Event Graph in
the My Blueprint tab to open a new tab. The Begin Play Event is where you can initialize any variables,
objects, widgets, etc. This is the beginning of this Item Object. Unreal will call this Event when the Play
button is hit for all Actors in the level, or it can be called when the level gets loaded.
Drag in the Cost variable and place the Set node next to Begin Play. Drag the execution line from Begin
Play and connect it to the Set Cost node. Now we need to set the value of Cost. Right click in the event
graph to bring up the search context menu. Search for Random Float in Range. Plug the Return Value
into the Set Cost node and set the MAX value to 1000.0. Compile. This will set the value of cost to a
value somewhere between 0 and 1000.0 when Unreal calls Begin Play.
Before we test it out to see if it works let’s print the value of Cost to the screen when we collide with
BP_Item. Right click next to the Event ActorBeginOverlap and search for Print String. Drag the Cost
variable from the My Blueprint panel and drop it below the Begin Overlap event. Call the Get this time
since we want to read the value and not set it. From the output pin of Get Cost drag it into the In String
pin. Unreal will automatically convert the float into a string for us. Navigate to the Level Tab and drag in
a BP_Item from the Content Browser and drop it into the scene. If you hit play and walk into the sphere
you should see blue text in the top left corner of the screen.
Another way we can make this look better is by adding a $ to the font of the text. To do this we can use
an Append node. Right click in the event graph and search for Append and select the one for string.
Drag off the Return Value from the ToText node and drop into the B pin of the Append node. In the
text field of the A pin add the $. Finally drag off the Return Value of the Append node and drop it
onto the Value pin of Set Text.
Test this in-game with 5 of the BP_Items placed in the level to see the text show up as the player collides
with them.
Once you have opened the project settings find the Input category in the left hand column. Since we
are going to run the code on a button press we can use the Action Mappings. Think of actions as just
that, actions that the user can perform, for example the base character could shoot, jump, crouch,
interact, etc. Each of these are input driven by the user, meaning they have to press a key to perform
said action. Once you open the action mappings you will see jump in there. Jump is the unique identifier
for this action but if we open that up we can see that there are multiple buttons we could press to
perform this action. Keep this in mind when you create the new Input. Add a new action mapping
called Find Highest and use the 1 key. Then add another new action mapping call FindLowest and
use the 2 key. You can set the keys by searching, but make sure you are targeting the keyboard.
Have the Character hold an array of items Now that we have the input we need to add
the data behind it. Navigate to the content browser, find the SideScrollerBP folder, open the
blueprints folder, and then open the SideScrollerCharacter blueprint. Navigate to the event graph for
the side scroller character. You’ll notice that the event begin play event node is not there in the event
graph. Epic decided that since the side scroller character didn’t need to initialize any variables that they
would just delete the call to Begin Play, we can simply fix this by right clicking and searching for the
Begin Play event.
Once you have added the Begin Play event right click again in the event graph and search for the Get All
Actors of Class node. Hook up the exec and set the class to BP_Item. Next we need to capture the
data but we haven’t made a container to store it yet. Let me show you another way to create variables in
Unreal Engine. Right Click the Out Actors pin of the Get All Actors of Class node. Select Promote to
Variable. Unreal automatically created the variable and called Set for us. This creates a brand new
variable every time you Promote To Variable so be careful using this, otherwise you could end up
creating multiple variables where you only want the one. Rename this variable to “Items”.
Add the Input Event to the Side Scroller Character
Now that we stored the data of all the Items in the level. We need to add the Input events so that we can
manipulate the data. Right click in the event graph and search for FindHighest it will be under the
category Input->Action Events. Do the same for Find Lowest. These events will be the entry point
right after the input key was pressed. While you can just write your code right here, we are going to
create two functions instead, and then have the input events call those functions.
Navigate to the My Blueprint panel. Find the Functions category. Hit the +(plus) symbol twice.
Select NewFunction_0 and hit the F2 key to rename it, call it FindHighest. Do the same for
NewFunction_1 and call it FindLowest. Select the FindHighest function again and take a look at the
details panel. At the bottom of the details panel you will see Inputs and Outputs for the function.
Inputs are the parameter list for the function. Outputs are the return type of the functions. You will
notice you can add multiple inputs and multiple outputs. Both FindLowest and Find Highest will have
no inputs. Both FindLowest and Find Highest will have an output of type BP_Item Object
Reference. Name the output for Find Highest, HighestItem; name the output for Find Lowest,
LowestItem.
Navigate back to the Input events in the Side Scroller Character’s Event Graph. Have
the input for find highest call the find highest function. You can do this two ways;
Search for Find Highest by right clicking in the event graph, or by dragging it in from the My
Blueprint Tab. Do the same for the Find Lowest Input Event calling the Find Lowest
Function. Next drag off the return item of each function and search for CostText Toggle
Visibility. Connect the Exec from the function call to the toggle node. This will toggle the
text on and off base on the button press.
Test to make sure pressing 1 shows the text for the highest cost item and pressing 2 shows the text for
the lowest cost item
If you find this task difficult make sure you ask for guidance on discord. However, we expect you to try
something out first. We will not be able to give you the answers, but we can point you in the right
direction. The more descriptive your problem is the better we can help you. “I don’t understand how to
do this pseudocode” is not an acceptable question so think critically when you are asking your questions
in discord.
Creating Backups
It’s very important to create regular backups of our work and close Unreal often to free up resources,
especially because we are not using any versioning control like Perforce. Since we’re at a good stopping
point (finished with the main portion of the document and tested it), let’s create a backup so we can
quickly restore where we left off if something goes wrong.
In Unreal, close out of any open tabs and make sure you’ve Saved All. Right-click the Content folder from
the Content Browser and show in Explorer. Once the Explorer window is open, close Unreal, I repeat
close UNREAL, closing out is Important to clear any files open for editing.
In the Explorer window, go up one folder into the project folder (will match the name of the project).
There will be four folders and a .uproject file. Select the Content folder and the Config folder. Right-click
one of the selected folders and choose Send to > Compressed (zipped) folder.
Rename the zipped folder to which document it corresponds to, in this case Assignment1.4 like so:
That’s it. You’ve now created a copy of your current progress. If something happens with your project in
the future, you can now replace any of the corrupt files in the project you’re working in with a known
working backup without losing much progress.
I recommend doing this after every document in the future. It’s similar to the submission procedure but
instead of submitting to FSO, you may consider copying it to some cloud storage like Google Drive or
Dropbox in case something happens to your computer. They are small in size, so by the end of the class
you will end up with about 30 backups at 30MB each, which is still less than a gigabyte total and will save
you loads of time if something goes wrong.