Unreal Engine 5.1.1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 46

Selim Msolly 3DNI1

Table des matières

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

13.7 Difference between a timer and a delay....................................................33


14 Action Mapping................................................................................................ 33
14.1 Pickup object.............................................................................................34
14.2 Spawning an actor.....................................................................................35
14.3 NudgeBall..................................................................................................35
15 Raycast (Linetracing in UE5)...........................................................................36
16 Widgets (UI).....................................................................................................36
16.1 Creating the widget and adding it to the viewport......................................36
16.2 Modifying the widget..................................................................................37
16.3 Updating HealthBar...................................................................................37
17 Transitioning between levels using widgets.....................................................38
17.1 Modifying the sound when hovering or clicking the button........................38
17.2 Creating the widget................................................................................... 39
18 Blueprint Function Library................................................................................39
19 Pluggin libraries............................................................................................... 40
20 Modelling tools.................................................................................................40
21 Examples......................................................................................................... 42
21.1 AddingScoreOnPickup..............................................................................42
21.2 DestroyAllActorsOnPickup........................................................................43
21.3 MovingFloor...............................................................................................44
22 Shortcuts..........................................................................................................44

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.

1.1 Pure FUNCTION

A pure function doesn’t have an execution pin because it returns the value
immediately.

4
Selim Msolly 3DNI1

1.2 Event tick

It is a function that is excecuted whenever a new frame is drawn

Example

2 Variables
We store data in variables

 Hold ctrl and left clic brings the get variable


 Hold alt and left clic brings the set variable
 Hold ctrl+alt and left clic brings the get and set variable

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.

3.1 How to create a structure

6
Selim Msolly 3DNI1

3.2 Creating variables in structures

4 Enumeration
4.1 Definition
It is a list of operations that are after executed.

4.2 Creating an enemuration list

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.

This example prints out my function is working

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.

5.7 Local variables


They are stored locally in the function. They are not global variables.

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

 Functions can be called from different blueprints, but macros cannot,


they are only called in the blueprint where they are created.
 Once a blueprint is created, I can drag it to the viewport to create its
reference.
 Functions created in level blueprints cannot be called in blueprints.
 Transform = location, rotation, scale,
 When I want to change viewport settings, I go to editor preferences and
then go to navigation.
 The function destroy is always put in the blueprint that will be destroyed.
 If there is anything regarding a score, it is put on the blueprint of the
character.

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.

It has execution pins

Select also does the job

8.2 Switch
It is basically like switch variable and then lists the possiblity case 0 then case 1
then…
14
Selim Msolly 3DNI1

It is generally used with enumeration

8.3 While loop

This example demonstrates as the following :

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.

8.4 For loop with break


Break is when we want the loop to stop

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.

8.5 Array (for each) : tables

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.

We can change the type of an array.

Note

 Array Element prints out the elements.


 Array Index prints out the position of the element.

16
Selim Msolly 3DNI1

8.6 Flip flop


Flip flop is a function that lets you alternate between two actions. For example it can
be used in a scope action; tenzel mara l fard ygamer tenzel mar okhra scope yetnaha

In this example, A is executed first and after a delay of second, B is executed.

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.

9.2 Object Oriented Programming


It uses a principle called class. An instance of a class is called object.

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

10.2 Get function


When a variable is set to private, we can not access its value from any other
blueprint. The way to read it is to make a function that does this job. Example of
function :

20
Selim Msolly 3DNI1

10.3 Set function


When a variable is set to private, we can not read its value from any other blueprint.
The way to modify it is to make a function that does this job. Example of function :

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.

10.4.1 How to spawn an actor in blueprint :


The function below spawns the actor after 2 seconds from pressing the play button.
This was coded in Event graph (main)

And below we define the BP_Pickup and what we want it to do

22
Selim Msolly 3DNI1

We can disable tick event after we press the play button

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

10.4.3 How to add collisions

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.

12 Basic Inheritance Hierarchy in UE5

25
Selim Msolly 3DNI1

13 Character
13.1 mesh
it’s the image that you want your character to appear into.

13.2 Changing default characters

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.

13.3 Adjusting camera position


Add a component named camera and adjust its position.

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

And then I do this to create the movement effect.

This is for setting the movement sideways.

28
Selim Msolly 3DNI1

And now we need to set the movement of the character so he can look around and
up.

Yawn needs to be attached to look around otherwise it won’t work.

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.

13.5.1 Adding variable and function

13.5.2 Changing player controller

31
Selim Msolly 3DNI1

13.5.3 Setting up the functions together

13.6 Polling
It means setting a timer on a function to loop.

32
Selim Msolly 3DNI1

This function stops the timer

13.7 Difference between a timer and a delay


A timer is much more accurate than a delay.

14 Action Mapping

33
Selim Msolly 3DNI1

14.1 Pickup object

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.

14.2 Spawning an actor

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

I collapsed all this code into a function called NudgeBall

Note:

The collision must never simulate physics.

35
Selim Msolly 3DNI1

15 Raycast (Linetracing in UE5)


Linetracing in UE5 is used for drawing a line from a starting point to an ending point.
If something hits the line, an event is triggered.

This example draws a line from the position of player to 500m forward.

16 Widgets (UI)
Components shown on the screen.

16.1 Creating the widget and adding it to the viewport

36
Selim Msolly 3DNI1

16.2 Modifying the widget

16.3 Updating HealthBar

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

And now in the BP_ThirdPersonCharacter, we make this

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.

17 Transitioning between levels using widgets


17.1 Modifying the sound when hovering or clicking the button

38
Selim Msolly 3DNI1

17.2 Creating the widget

18 Blueprint Function Library


Function Library are functions that can be called in any blueprint and they are not
related to objects.

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

I can drag objects from this menu.

I can change its pivot from this tab.

All objects are stored in this folder.

41
Selim Msolly 3DNI1

This tool allows us to create custom objects.

The pivot is used to modify the angle of rotation.

21 Material
21.1 Creating Material

42
Selim Msolly 3DNI1

21.2 Modifying the color

21.3 Importing a texture

We import the texture by dragging it the the material graph.

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

Select group of function +c = group them and say a comment

B+left click= branching

S+ left click= sequence

D+left click= delay

F2=rename

Alt + left click= removes the connection between functions

46

You might also like