0% found this document useful (0 votes)
20 views

UnrealBasicsAssignment

The assignment focuses on using Unreal Engine 5.0.X to explore arrays, create custom classes, and implement game mechanics through Blueprints. Students will learn to add actors, variables, and input mappings, as well as display information on screen and manipulate data using functions. The document provides step-by-step instructions and resources for successfully completing the assignment.

Uploaded by

lpstudios17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

UnrealBasicsAssignment

The assignment focuses on using Unreal Engine 5.0.X to explore arrays, create custom classes, and implement game mechanics through Blueprints. Students will learn to add actors, variables, and input mappings, as well as display information on screen and manipulate data using functions. The document provides step-by-step instructions and resources for successfully completing the assignment.

Uploaded by

lpstudios17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Scripting for Designers 1 Assignment 3

Array’s in Unreal Engine 4

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

(scroll down for instructions)

It’s recommended to uncheck Print Layout when viewing these documents:

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

Download and open the SCD1 Starter Pack


First thing you will need to do is navigate here on google drive and download the
SCD1_StarterContent.zip. Once you have downloaded this; extract it, and open it up by double clicking
the Unreal Engine Project File.

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.

Review the built in tutorial


Once you have the engine open in the top right hand corner of the window select the graduation cap
symbol to open the Unreal Engine walkthrough. This describes a bit about how things are set up and at
the end it directs you to the other built in tutorials which can be quite helpful if you haven’t actually
opened Unreal Engine before. Go through as many as you need to familiarize yourself with how to
navigate around the Unreal Engine. Also check out the additional links above to review the badges you
received last month or earlier this month as needed.

Adding a folder to the project


Navigate to the content browser. If it is not showing by default, you will need to add a window for it
to your project. Select the “Window” option, then “content browser”. Click on “content browser 1”.
You should see a new window added called “content browser”.
Click on the content folder in the sources panel to navigate to the root folder. Create a folder named
LastName_FirstName; replacing LastName with your last name and FirstName with your first name. This
will let us know whose project we are working in or grading. To do this right click in the content browser
window on the right anywhere in the free space. Be careful not to accidentally right click a folder that is
already there.
Select New Folder at the top of the context menu. If you accidentally clicked off the folder before naming
it you can right click the folder to rename it or select the folder and press F2. Feel free to add as many
folders as you want to help yourself stay organized. However, if you only have one asset inside a folder
you don’t need to create a folder for it. Typically you will see an Art Folder, Blueprint Folder, and a Maps
Folder. Any other folders beyond that is up to you. Typically I only create folders as I need them. No
need to preload your folder structure unless you are doing prep work for a large project.

Adding your first Actor


If you hit the play button at the top of the screen right now you’ll notice that you can run around and
jump. This is the side scroller template provided by Epic Games. When you are done, hit the Esc key
to stop playing.
If you haven’t already; inside of your named folder create a folder called Blueprint and open that up.
Right click in the content browser and select Blueprint Class. You will see a new window popup.
Select Actor and name it BP_Item. Double click it to open it up.

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.

Adding in-game feedback with a Text Rendering Component


Now we are going to have it display the value of cost to the screen in game rather than use the
print string. On the components tab, add a TextRender Component and name it CostText.
Navigate to the viewport tab. Move the text up in the world so it is above the sphere. Over in
the details panel rotate it 180 around Z. Change the font size and color as desired. Begin play
should toggle visibility for the cost text so it starts the game with the text hidden. To do this drag
in the CostText component and place it next to the Set Cost node. Drag off the return pin and
search for Toggle Visibility.
Now we need to set the CostText->Text to the value of Cost. To do this Drag off the Get pin for our
CostText component. You can reuse the previous pin from Toggle Visibility, or drag in a new get pin
for the Cost Text component. Drag off of the pin and search for the node Set Text so that we can call
it. Then hook up the Exec from toggle visibility to the new node. Finally Drag off the return pin from
the Set Cost node and drag it into the Value pin of Set Text. Just as with the print string node, Unreal
Engine will automatically convert the float value into what we need for the Set Text node, the data
type Text, using a To Text node.
Let’s get rid of the Print String node, you can do this by clicking on the node and hitting the delete key or
right clicking the node and selecting delete. Delete the Get Cost node and the conversion node as well.
Drag in the CostText component from the Components tab and place it below the Event
ActorBeginOverlap. Next we need to get the Event ActorEndOverlap from the sphere. To do this right
click in the event graph and search for ActorEndOverlap. Place that node below the Get CostText
node so that node is surrounded by the two Events. Drag off the Get CostText node and call Toggle
Visibility. Plug both event execs from the overlap nodes into this toggle visibility node. That way
when we collide with the sphere the text will display and when we leave the text will disappear.
Cleaning up the displayed text
If you test it now you will see that it works, but you will also see three digits after the decimal place. This
doesn’t look good. We can fix this by using the advanced float to text node to specify the number of
digits so it only shows 2 fractional decimals. To do this navigate to the Begin Play Event where we set the
text for CostText. Right click the pin for Value on the Set Text node and select Break all Pin Link(s). We
are going to add some more code between the To Text node and the Set Text node. Hit the drop down
arrow on the To Text node. Set the Minimum Fraction Digits from 0 to 2 and Maximum Fractional
Digits from 3 to 2.

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.

Add Action Input Mappings to the Project Settings


We are going to create two functions; one that searches for the Highest Cost and one that searches for
the Lowest Cost. It is going to be driven by input. When we press 1 it will run the Highest Cost search, and
when we press 2 it will find the Lowest Cost. To do this we need to modify the project settings. To open
the project settings goto the edit drop down at the top of the screen and you should see it towards
the bottom of the drop down menu.

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.

Fill out the Functions


This ends the guided walkthrough portion of the lab. For the final steps of the lab it is your
responsibility to take this pseudocode and convert it into code. I have provided the pseudocode for both
FindHighest and FindLowest functions. Things to look out for: you can use either the For Loop or For Each
Loop nodes for this assignment, the return node needs to be called after the loop has looped through all
the objects in the items array (a foreach loop is recommended as that is what the pseudocode logic uses).
Take each line of the pseudocode and break it down into logical steps. Look for keywords like “Set” or “For
Each”; these will give you hints on what node to call.

For Highest use the following pseudocode for the logic:


Set a local variable named curHighest to the first item of the Items Array
For each Element in Items
If Element.cost > curHighest.cost
Set curHighest to Element
Return curHighest

For Lowest use the following pseudocode for the logic:


Set a local variable named curLowest to the first item of the Items Array
For each Element in Items
If Element.cost < curLowest.cost
Set curLowest to Element
Return curLowest

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.

You might also like