Unreal Engine 5.1.1
Unreal Engine 5.1.1
Unreal Engine 5.1.1
1 Functions...............................................................................................................3
1.1 Pure FUNCTION.............................................................................................4
1.2 Event tick........................................................................................................ 4
2 Variables................................................................................................................5
3 Structures..............................................................................................................5
3.1 How to create a structure................................................................................6
3.2 Creating variables in structures......................................................................6
4 Enumeration..........................................................................................................7
4.1 Definition.........................................................................................................7
4.2 Creating an enemuration list...........................................................................7
4.3 Example..........................................................................................................7
5 Functions...............................................................................................................8
5.1 Definition.........................................................................................................8
5.2 Implementation...............................................................................................9
5.3 Input................................................................................................................9
5.4 Example........................................................................................................10
5.5 Output...........................................................................................................10
5.6 Example........................................................................................................11
5.7 Local variables..............................................................................................11
6 Macros................................................................................................................ 12
6.1 Example........................................................................................................12
7 Collapsed Graph................................................................................................. 13
8 loops....................................................................................................................14
8.1 Branching (if condition) and select................................................................14
8.2 Switch........................................................................................................... 14
8.3 While loop.....................................................................................................15
8.4 For loop with break.......................................................................................15
8.5 Array (for each) : tables................................................................................16
8.6 Flip flop......................................................................................................... 17
1
Selim Msolly 3DNI1
8.7 Do once........................................................................................................ 17
9 Programming Languages....................................................................................17
9.1 Procedural Programming..............................................................................17
9.2 Object Oriented Programming......................................................................18
10 Classes............................................................................................................ 20
10.1 Objects...................................................................................................... 20
10.2 Get function...............................................................................................20
10.3 Set function............................................................................................... 21
10.4 Actor..........................................................................................................21
10.4.1 How to spawn an actor in blueprint :............................................................................22
10.4.2 How to add an actor in blueprint so it shows up when i press play button..................23
10.4.3 How to add collisions....................................................................................................24
11 Casting.............................................................................................................25
12 Basic Inheritance Hierarchy in UE5.................................................................25
13 Character......................................................................................................... 26
13.1 mesh..........................................................................................................26
13.2 Changing default characters......................................................................26
13.3 Adjusting camera position.........................................................................26
13.4 Movement..................................................................................................27
13.5 Sensitivity.................................................................................................. 30
13.5.1 Adding variable and function........................................................................................31
13.5.2 Changing player controller............................................................................................31
...................................................................31
13.5.3 Setting up the functions together.................................................................................32
13.6 Polling........................................................................................................32
2
Selim Msolly 3DNI1
3
Selim Msolly 3DNI1
BLUEPRINT
1 Functions
In blueprints we have pins : these icons :
The while dot is an execution pin, it connects functions. The function on the
right will be excecuted when the one on the left is triggered.
The blue one is a target pin. The function needs to be connected to a
reference (pointer that points to an actor)
The result of this function is not executed immediately because it is not a pure
function. The result is stored in memory.
A pure function doesn’t have an execution pin because it returns the value
immediately.
4
Selim Msolly 3DNI1
Example
2 Variables
We store data in variables
5
Selim Msolly 3DNI1
3 Structures
It refers to a group of variables. It also can be used so that a variable will take that
stucture as a type. One variable storing multiple variables.
6
Selim Msolly 3DNI1
4 Enumeration
4.1 Definition
It is a list of operations that are after executed.
7
Selim Msolly 3DNI1
The first item is mapped for 0, the 2nd for 1 and the 3rd for 2. So we always start from
0
4.3 Example
This prints the fruit and a message according to the chosen fruit in advance
The screen shot below show another short way to medelise the problem
Select makes us able to type a text according to the chosen item all in one block
8
Selim Msolly 3DNI1
5 Functions
5.1 Definition
A block of code that adds functionnaly to the code
5.2 Implementation
We define a function and we tell it what it is supposed to do, and then we call it in the
event graph which is like the main class.
9
Selim Msolly 3DNI1
5.3 Input
In a function we can define an input which is like a parameter in a function
In this example I defined an input called Points whose type is Integer and by default it
takes the value 0. So when I print out the Points parameter with the function print
string it will show me 0.
5.4 Example
This example takes a parameter called health in input and checks if it’s value is equal
0 then show a message hehe u dead otherwise it shows u’re safe this time.
5.5 Output
The return value of a function
10
Selim Msolly 3DNI1
5.6 Example
This function has an output called dead. It is set to true if the value of health is equal
to 0. The tick of the parameter Dead wil indicate that Dead will show True.
11
Selim Msolly 3DNI1
For example the parameter U dead ? is an input of the funtion which means it is local
the that function. Another example here is Khamouja a local parameter that we
added into the function Karma Is ABitch.
6 Macros
Macros are functions but with more options. For example we can create a delay
function in macros. They also have unputs and ouputs.
6.1 Example
12
Selim Msolly 3DNI1
This code will be executed according to a defined sequence. At first it will show We
are performing magic now and then it will show I hope you are enjoying the show.
After 5 seconds (delay) it will show the show is over.
Note
7 Collapsed Graph
It is a way of grouping a code into one block. It’s just for esthetic reasons and for the
code to look cleaner.
13
Selim Msolly 3DNI1
8 loops
8.1 Branching (if condition) and select
It takes true or false as an input and for the ouput it either have true or false.
8.2 Switch
It is basically like switch variable and then lists the possiblity case 0 then case 1
then…
14
Selim Msolly 3DNI1
If the number is between 0 and 10 print it out and add 1 to it. I just need to
understand why while adding the number variable and the ++ incrementation at
the end it will no longer be an infinite loop.
15
Selim Msolly 3DNI1
This example takes the numbers between 1 and 100 multiply it by 2 and them
compare it with 100. According to the condition, an action is made.
In this example I created a variable named number and I change dits type to array,
and then I printed all the elements of it.
Note
16
Selim Msolly 3DNI1
8.7 Do once
It’s a function that executes an action only one time. But if the action reset is
triggered and there is another entry it will be triggered again.
9 Programming Languages
9.1 Procedural Programming
The approach uses functions. The whole program is structured in functions
17
Selim Msolly 3DNI1
In this approach we don’t have a unit caracterizing a character. In this example when
we call the function move we don’t have which character we should move. So, this
entire code isn’t reusable.
All data is encapsulated in a class. After we can derive objects from it (instances).
18
Selim Msolly 3DNI1
In this approach we have a unit that identifies a character and then we can instantiate
character i. We don’t have to write all the code all over again. Character i is an object.
Example
19
Selim Msolly 3DNI1
The class actor has a method called set actor location, via the target the pin the
moethod needs to know on which actor this method is going to be called. This is
called instantiating.
10 Classes
When creating a blueprint of type object we don’t have the begin function.
Instead we can hover arround the function menu and select custom event
This lets us define our own function but does not return anything
10.1 Objects
20
Selim Msolly 3DNI1
In other words when i want to change the value of a variable that is private, I make a
set function with input parameter and then i relate it to the private variable.
10.4 Actor
When creating an actor, 3 windows pop up ;viewport,construction script and event
graph
Here i created an actor called BP_Pickup and i dragged it two times into the viewport
so it created two actors. This is why when i call a print string in the event graph to
print a string it is printed two times (the number of actors present in the viewport)
21
Selim Msolly 3DNI1
But the action needs to be called when the actor is created and not when the begin
play is pressed.
22
Selim Msolly 3DNI1
10.4.2 How to add an actor in blueprint so it shows up when i press play button
When adding a component we choose static mesh for pickable objects and skeletal
mesh for animated characters. The component which is higher in the hierarchy is
called the root. When we want to apply physics law to it, it needs to be the root.
When enabling physics on a static mesh, it will apply to all physics’ laws
23
Selim Msolly 3DNI1
And this this example below an event is triggered every time an actor overlaps the
collision. In this case it print hello
24
Selim Msolly 3DNI1
11 Casting
Actors are a derived class from another class called pawn. When we are in an open
world, we are just moving the camera, the camera is actually a pawn.
Cast to pawn is a function that verifies if the actor is a pawn or now and
according to that an action is performed. In this example if the actor is a pawn,
when overlapping it will print out hello else i twill print out not a pawn.
25
Selim Msolly 3DNI1
13 Character
13.1 mesh
it’s the image that you want your character to appear into.
Under world settings, and exactly under gamemodeoverride we can change the
character shown by default in the game. To keep things clear, I created a blueprint
class of type gamemode and I named it BP_Gamemode and then I set the default
pawn class to the blueprint class of my character.
26
Selim Msolly 3DNI1
13.4 Movement
To move the character, we need to define inputs for mvoving, this can be found under
project settings input axis mapping.
Here I created two input axis for moving horizontally and vertically.
27
Selim Msolly 3DNI1
28
Selim Msolly 3DNI1
And now we need to set the movement of the character so he can look around and
up.
After that we need to attach rotations to the character. We add this by accessing use
controller rotation pitch. But this method will rotate the whole character and not only
his spine. To correct it we need a rotation animation which we will do later on.
29
Selim Msolly 3DNI1
13.5 Sensitivity
We add the multiplier, and we multiply the function by the sensitivity desired.
30
Selim Msolly 3DNI1
For the sensitivity, the multiplier needs to be initiated every time the character is dead
(if we play in a deathmatch) that’s why we’re going to set the BP_Character to a class
and it will be called every time the character is dead.
31
Selim Msolly 3DNI1
13.6 Polling
It means setting a timer on a function to loop.
32
Selim Msolly 3DNI1
14 Action Mapping
33
Selim Msolly 3DNI1
I added this part so that every time a pickup is nearby, and the key F is pressed, the
object is destroyed.
34
Selim Msolly 3DNI1
Also, I created a variable in BP_Object which name is health point, and whenever the
key is pressed and before the object is destroyed, we will print the value.
This function spawns an actor to specified coordinates, and when the variable is set
to expose on spawn and set to editable, we can edit the variable via the function
directly.
14.3 NudgeBall
Note:
35
Selim Msolly 3DNI1
This example draws a line from the position of player to 500m forward.
16 Widgets (UI)
Components shown on the screen.
36
Selim Msolly 3DNI1
We divided the input by 100 because NewHealth is a variable between 1 and 100
and the function set percent stores values between 0 and 1.
37
Selim Msolly 3DNI1
Clamp is a function that sets the minimum and the maximum of a variable.
Now I added this code, so it prints the value of my health and updates it next to the
healthbar.
38
Selim Msolly 3DNI1
39
Selim Msolly 3DNI1
19 Pluggin libraries
It is basically a set of libraries that I can install from the market of unreal engine to
import functions that are already built by other players.
20 Modelling tools
We click on Modeling when selecting this.
40
Selim Msolly 3DNI1
41
Selim Msolly 3DNI1
21 Material
21.1 Creating Material
42
Selim Msolly 3DNI1
43
Selim Msolly 3DNI1
22 Examples
22.1 AddingScoreOnPickup
44
Selim Msolly 3DNI1
22.2 DestroyAllActorsOnPickup
22.3 MovingFloor
When adding a track, always choose a float track because I can modify it later.
45
Selim Msolly 3DNI1
23 Shortcuts
Ctrl+D = Duplicate
F2=rename
46