Hello, this is Younghoon Lee
Today we will be working on collisions and the game over function
In this chapter, we wil learn about how to set the channel for collisions
And how to process at C++ using this method
And we will also learn about how to
Make the collision between Player and enemy into the game over state
Processing Collisions
Unreal Engine has Physics, a physics engine
With which we can process collisions
In order to process collisions
We need to start with some prerequesitory things
First is the concept of channels
Go to Edit
Project Settings
And at Collision, we see these
Object and Trace channels
Object Channels is where
They process physical collisions
While Trace is where they process
Things such as the gaze direction
Today, we will be using Object Channels
In processing collisions
The first objects that appear
We have Player, Bullet and Enemy
So using that
Let's reconfigure this
So first is Player
And it says Default Response
Which asks for default settings for
The Player channel with existing channels
Let's say Overlap here
And we have Bullet
Bullet
We also need Overlap here
And finally, let's say Enemy here
And now we need detailed setups for this
Let's start with Enemy
Here, what we will try is
Let me explain more about this later
Let's visualize what we are going to do
So we have Enemy
And Player and Bullet
So Enemy checks for Player
And Bullet checks for Enemy
That's the collision check that happens
So first, let's start with Enemy
At Enemy, this is what it looks like
We first need to se this Box Component
Over here, like so
It says OverlapAllDynamic
Let's put it to Custom
So here, what corresponds to Collision Channel
What corresponds to Object Channel is Object Type
So open it here, and it says this here
Let's start with Enemy
And then it says Collision Enabled
And there are two in general
It has Query and Physics
Query is what overlaps, it simple detects
So it won't push things around
It just detects the overlap
And Physics is something physical
It collides into something and pushes it away
Let's check for the two here
Let's set it up so that it detects both Query and Physics
And for Enemy, like so
The actual collision will happen
Between Enemy with Player and Bullet
Here, I won't use Block and only use Overlap
Let me explain a bit more about this situation
As you just saw, here's the diagram
When we say there are two objects like so
We can set for their collision settings
For example, Object B
With Object A, it will be Ignore
So let's write this out here
When we have A and B
At A, it will Ignore B
And then at B, it will Block A
Let's say that this is the setup
Then what happens in the end is
Ignore is what happens
And here at the diagram
Here, let's take it as it is
A is Ignore, and B is Block
But the result for that is Ignore
That's how Ignore and Block work
So Ignore literally ignores
So Overlap isn't a physical collision
While this is an actual physical collision
And the priority goes like this
Ignore is at the top
So if either of the two is Ignore, it becomes Ignore
And if it is Overlap and Block
It will end up being Overlap
So we can set all these here
And let's set it up for Player as well
Select Box Component
Come over here for customization
Let's say Ignore for all
And then for our Player
Let's set it up like this
Player will only Ovlerap with Enemy
That's how we can set this up
And we have Bullet as well
For Bullet, select Box Component
And customize Bullet as well
And then, Ignore here and
For Bullet, let's say it only Overlaps with Enemy
Then Enemy overlaps with Bullet
And Bullet overlaps with Enemy
So it is Overlap for both
That's how we set this up
Let's save everything here as well
And then
Let's try colliding into them
And we can't really see if it is happening
So in order to process this
Let's come over to Enemy and do that actuall collision
We can first check for it at Blueprint
So at Enemy
We had this ActorBeginOverlap here
This detects any collision between actors
And it has no detailed content to it
And we have a scenario we want
Let me visualize it here
For example
Let's say there is some boss, like a golem
And let's say we want to shoot here
And smash its arm
Or let's say we want to shoot its head
Or some parts and destroy it
For this to be implemented
It is hard to realize this
Only using our ActorBeginOverlap here
It is very hard to detect where
The 'where' of the hit
We can't really use coordinate calculation for this
So instead, we could
At this component
This collider
Get to the bottom of the collider
And here is a function that detects
Whether that collider has been collided
So using this
We can use collision detection for each collider
So at C++
We can demonstrate for these two
So at its code
Let's go to Header first
Starting with Enemy
Let's say this below Tick
Virtual Void NotifyBeginOverlap
There's that
And Actor's OtherActor, like so
We have a parameter like so as well
This function is same as the node we saw
At Blueprint in serving the same role
So let's implement this
And then over at this side
Let's print the log
At Unreal, to print log
We can use the macro 'UE_LOG()'
So write 'LogTemp'
And then 'Warning'
And this Warning is printed in yellow
Which is very visible, so let's say Warning
Let's say Text
And let's just print something for the sake of it
Let's print this text over here
So that's how we code it
Over at Unreal, let's compile
So run it and collide into it
And let's see if it prints the log
So here we see how this log is being printed
Let's take a look at it with this fixed
Again
So, when we collide into it
We see how it prints the log
So, we could use this function but
As I mentioned before
Let's try collision per parts
So let's make this log a comment
And again
Over here at Header again
The component that processes collision here is
Our Box Component
So whenever Box Component experiences any physical collision
We can create a function so that this gets recorded
And it will let us know in case of any collision
That's how we can process collisions
So back to our Enemy actor's BeginPlay
Its BeginPlay is pretty long
Let's write it out at the bottom
Let's start at the very bottom of our BeginPlay
At Box Component
Whenever there is a collision
We'd like to know, right?
So let's say, BoxComp
And then, what we want here is
Looking at the list of its property and function
We have a function called OnComponentBeginOverLap
Over here
So that's how it looks like
In fact, it's less of a function
Than it is a delegate
So a delegate looks like this, when we follow it along like so
So it says FComponentEndOverLapSignature
And if we enter there
It says Declare Dynamic Multicast
So it says it is a delegate
It says it is a delegate with six parameters
So we can shape this into a function
And add this function
So it says six, over here
Parameter, its variable name
This is a pair for each
So let's count it using the commas
One, two, three, four, five, six, and that means it's twelve
So it ends over here
So let's copy all the way from here to there
And then, let's come back over here
Back at Header
We will create a function we'll add
Let's add it right at the bottom
And the function we'd like to use added as delegate
Needs a macro called UFUNCTION
So write out UFUNCTION over here
And for this void
This is BeginOverlap of our Box Component
So let's write out onBoxCompBeginOverlap
And the one we brought in,
Let's paste the one we copied
And it should end with a semicolon
And then here
We can delete the comma to the right of our data type
So that's how we can shape it
Let's implement it, we can work with the implementation like so
And let's see if it prints out well
Let's also print this part as a log
Like so, and
Now we need to add this function
In order to add the function
Let's add it at BeginPlay
The one we didn't finish, right?
We will add it over here
So add a dot here
And wirte out 'addDynamic'
And then here, the parenthesis
This, and ampersand, and the address to that function
That's how we add it like so
Then, whenever there is a collision
It will call this function
So, after we've written out everything
Let's compile first
It may or may not work
If it doesn't work, you can simply restart
Restart, edit it once again
And let's see, we know that the event is alright
And then, remember the one we wrote out here?
Starting with Enemy
We set things up at Box Component like so
Let's try writing this part out at our code
So over at Enemy, let's go to our Enemy constructor
So we'll be writing over here
And what we want to do here is
First, for Mesh Component
We'd like to disable the collider
Meaning, we'd like to make the collider 'off'
And at Box Component
We'd like to add
The collision settings
Let's work on each
Let's try our MeshComp
At set Collision, we have things like Enable
At Set Collision, we have a few like so
And here, Enable is for on/off
Over here at the top, we have No Collision
Meaning, its collision won't be processed
We can set it up separately like so
And let's look at our Box Component
Let's work on one by one, over here
We have Generate Overlap Event
This should be enabled
In order to detect collision
So this needs to be on
So let's call the function SetGenerateOverLapEvents
SetGenerateOverlapEvents
And first let's set this as 'true'
And then we'll set up our collision
Let's do the same thing as we've done for Set Collision
Enabled
And let's enable both Query and Physics
In fact, we only need Query
But let's just try enabling both
And then
We need to set up its collision channel
Over here, it is set up as Enemy
So let's try setting it up over here
We can add SetCollisionObjectType here
But over here, what it says is
Its name is looking like this
So we need to look it up once, right?
Back to our Project
Let's look at the folders
Over here, we have a folder called Config
This is a very important folder
Config, Content, and then Source
These three folders are very important
At Configt, we have the DeafultEngine.ini setup file
Ini file is for Initial file
So let's try and edit this
And try scrolling to the bottom
And we see Player here
Player, Bullet, Enemy
These things we set up are all in here
But the name that should actually be used is
The channel names we have over here
So this channel name says
ECC_GameTraceChannel1
So we have 1, 2 and 3
In the order of Player, Bullet and Enemy
So we should remember that
And let's write that over here
So 1 is Player, this is 3
Enemy was 3
So we write it up like so
And then, what we did here is
Overall
Ignore for everything, and then
Only the ones I want to enable
Become Overlap like so here
That's how we process it
And we could do it like the following
At Mesh Component, we have
SetCollisionResponseToAllChannels
It means all channels are Ignored at once
And now we can set each channel separately
At SetCollisionResponse
We see the individual channel here
We can set it up using this
So here, we have the channel
And then the Response Time
So it starts with an 'E'
Meaning, it is Enum type
So these are Enum type over here
So we know that all Enum types start with 'E'
Anyhow, we need to write it up like this
1 and 2 are to collide
That's what we want to say, and then
Overlap will happen at the second argument
That's what we can set up like so
Let's make another one
And it can Overlap with 2 as well
That's how we can set up for its collision
In a way, we have this concept and another for setting up the whole
That's what we have here
But this will give us a lot of lines for the code
So in order to abbreviate this a little
Because if we repeat everything like so
The code becomes too long and there may be typos
So at Unreal Engine, in order to abbreviate all this
They provide something called Preset
So let's create these three into presets and add them here
So go to New, and let's say Player
And let's set it as Query and Physics
And Object Type, Player
And Ignore for everything
And say it only Overlaps with Enemy
And let's do the same for all others
For Bullet, same thing
Ignore everything, but only Overlap with Enemy
And finally with Enemy
Let's also go for Query and Physics
Set its type as Enemy
And Ignore
And for Bullet and Player
Let's have them Overlap
So we are done with creating the presets
And all we need is to assign the presets here
Let me demonstrate here
What we had to do was customize each and everything
But now, open it up here and see
Let's compile first beforehand
So here we have all presets for Player, Bullet and Enemy
So since this is Enemy here
Set it up as Enemy
Then it automatically sets it up
So that it fits the type for Enemy
So let's actually try it at the code
So after having done this
Let's close Unreal and restart
So let's make this a comment
When you make something in to a comment, select the part
And use Ctrl K+C, K+U
It's over here
And then our Mesh Component
Let's see the list that has it
Here, SetCollision
It says 'ProfileName'
Preset is this profile
So we need to add this
Here, say Text
And we can use the name as it is
Pay close attention to case sensitivity
It's 'Enemy' here
So write it out like so
Same thing, copy everything here
And let's do the same for Bullet and Player
Let's lok at the constructor for Bullet, paste everything
Bullet over here
We can write it out like so
And then copy it as it is
Back to Player, at its constructor
Let's write it out
Here, Player
And let's compile
You can do Ctrl B to compile
And you can do Ctrl F5 to restart it
So you could click on this or
Click on thie button at Debug
So we have it here
Let's check each here
At BulletActor
Let's go back here
Oh, it doesn't support this here
Let's do it manually then
Bullet
Enemy
They are not set up right
Right, this isn't set up correctly
Let's close it for now
It's not Mesh
We need Box Component
But it says Mesh, which isn't right
So let's change everything here
For Profile, we need to assign something out of Box Component
It's also not written correctly
Yes, this is the right way to do it
This here as well
I realize that I didn't copy this
So let's do it again here
So this is what it is
I said 'Box' but I wrote 'Mesh' here
Same thing here
Let's write it out here
Looking at it again, starting with Enemy
For Mesh, we disabled the collision
And we enabled it for Box
And for the class at Enemy
We set the profile for its collision settings
Same with Bullet
Let's build it again
And run it
So as of its content
Now it looks alright
It says Bullet here
So, Enemy too
It's set up nicely as we can see here
Let's go back here
And now it's set as Player
So that's how we set it up here
Let's check if Mesh is off as well
For Mesh, this Collision Enabled
We can see how it is set as No Collision
So now it is working as it should
So let's run it
Let's see if the log is printing
Yes, we see how it is printed
So now we need to actually process it here
So a while ago, we said this is our plan
Enemy destroys Player
And Bullet destroys Enemy
So let's start with Enemy
Enemy
Let's come over here, and the actual part for collision is here
So here
Let's say, if
Other Actor
If this Other Actor is
Our Player
Then you die
And I die
Right
So if
Let's start with the cast
When we process something like this
When we verify what Other Actor is
We have a few methods
We could use a tag or
We could use the name and compare with the letters in it
Or we could use its type and cast it
To test if that is the right type
Let me use the casting method here
So let's say 'Cast'
And let's do this
Cast is a function that looks like this
And then here
We write the data whose type we want to change
For me this is APlayerPawn
So here, it would be Other Actor
And then we will accept this
And then, of course we receive it as APlaywerPawn
And it's too much work to write this out every time, right?
If we say Player every time
So usually we just write out 'auto' like so
It's a pointer, so you could say this
Write out 'Auto'
Then with 'Auto' it automatically does this
Try hovering over and it looks like this
It accepts it as this data type
Since it's a pointer, let's add this
So is this Player or not?
We can ask, if nullptr
This asks if this is not Null
Instead of using the equal sign
So if this is not Null
Then this Other is PlayerPawn
Then we work with 'you die' and 'I die' parts
I should've added the header here
Player Pawn header is added here
So this part destroys Player
Let's use Destroy
And then for 'I die', I is 'this'
And we write out Destroy like so
And we can omit 'this' here
You could do it this way as well
It's the same thing
So let's use this same structure for Bullet as well
Then for Bullet, since this function is not implemented yet
Let's copy the structur of the function at Emeny as it is
And paste it right here
Let's add it below Tick here
And then we add the implementation
We repeat the same thing
And then over at BulletActor
At BeginPlay let's request it from Box Component
'Dear Box Component, let me know when you collide'
OnComponentBeginOverlap
And let's add AddDynamic
Let's write it out like so
Let's add 'this' next
And then ampersand
And we add the whole name for the function
So over here, we have it here
So we can copy and paste it right away here
And then over here
Here, the Other Actor
If this Other is Enemy
we want 'you die' and 'I die' parts
So let's do this
Let's change it up a little
Here, we used the function 'cast' here
And once we get into this function
Let's get in there like so
Actually, we can't do that here
Let's try it here, where we worked at before
Let's check into our 'cast' function
It looks like this
ANd then, finally
This if statement says
It says 'is a'
When we talk about class
There is a concept of relationship
When we say Object Constraining Programming (OCP)
At OCP, there is this concept
Let's visualize a class
We have the parent
And the child
And we say the child inherits from the parent
This is the 'is-a' relationship
The is-a relationship
So the child can turn into the parent
Or the parent type into the child
This casting is available
To enable type casting
It should be in this inheritance relationship
This is the is-a relationship
And let's say, this child
Let me take as an example...
Let's say a knife
Let's say that there is a class called knife
As instance variable, let's say
This child has the knife
Then this child and the knife aren't in is-a relationship
It's not the inheritance relationship
This kind of relationship is called 'has-a' relationship
The 'has-A' relationship
This is the two types of relationship here
So is-a relationship is, in the end
The relationship that enables for casting
That's why we can verify by checking if it is an is-a
So let's use that here
Here, instead of cast, let's try this
So if, this OtherActor
If OtherActor, is-a
There's this function here
It's the template here
Let's do this
And here, I write the data type I want to verify
This asks if you want to work with Enemy here
So it asks 'AEnemyActor'
So if this is true
We proceed with 'you die' and 'I die'
With the casting, this is what we get
If I want to verify various types
Then more if statements have to be
Added down here like so
But using is-a, we can simply use 'else if'
So you have a choice between these
I will try this method
Same thing, for 'you die' and 'I die', at OtherActor
Destroy
And at 'this', Destroy
I'll write it out like so
So this is done
Since we edited this part
We should restart it
Let's restart
And now let's run
Let's try shooting
When the two meet, they get destroyed
When they touch, they get destroyed
So it is working well
Making Game Over
So now that we have the collision settings
Let's make the Game Over screen
In order for a Game Over
We need to make things like its UI
So let's make a widget here
At Unreal, whatever processes UI is called widget
And usually the full term is 'Unreal Motion Graphic'
So a UMG
Let's creat one
Right click
Here's User Interface
Let's go with Widget Blueprint
See how it is inheriting our UserWiedget class
Meaning, if we are to create the class with C++
It will inherit the User widget
And that will be inherited back to this Blueprint
So that's the plan for us
So let's go to Tools and create a class
Choose All Classes here
And write it out here
'Userwideget'
It's here, right?
Click on this and go to 'Next'
Since we are working with Game Over here
Let's write GameOverWidget
Let's Create
And it is created here
Load it and it gets created here as well
Yes, this is how we make it
So let's begin with the work that is visible
Let's start with that
So choose our GameOverWidget
And create its Blueprint, like so
But actually, this is a lot of work
So let's go over here, and instead of Blueprint
Let's go with User Interface here
And we'll swap the parent
So at User Interface
We're back at that Blueprint folder
Right click here
Select User Interface
Click on Widget Blueprint
Then we get our User Widget
But here, at All Classes
Let's write it out here
So GameOverWidget is here
Let's write it out here
Select to create
So since this is a Widget Blueprint
Let's use the prefix 'wbp
So this is for Game Over
So let's call it WBP_GameOver
Let's save here
Let's start editing
Let's plan on this screen visuals
First, what we will do is
We will do it like so
We start with this box at the background
We will make it a little transparent
And we will write out 'Game Over'
Maybe in English?
Game Over
With that text, and then
Here, 'Quit'
And here, 'Restart'
These are the two buttons we will add here
That's the UI of the screen
This is simple
Let's try it here
We will start with adding a panel here
Over here at the bottom you have Panel
It must be hidden in the dropdown menu
So try opening it up here
And we have Canvas Panel
Let's drag and drop
And let's create it here
Then this gives us a section like so
And then, at the bottom right
Drag on this cursor and
We can adjust the resolution
I will go with the default resolution
And work with this 1280x720 one
And we will add a back panel
In an image
Like so
Let's make it around 1200x800
Around 1200x800
And let's set it as 0.0 for now
So then this is what we have
So over here
We have this flower-shaped thing
This is called an anchor
This anchor is at the top left
Then what this wil do is
Whenever we change the resolution
This is what happens
This becomes the anchoring point
So the top left is the anchoring point
Since there are many options for resolution
I recommend working with variable or adaptive resolution
And what matters in that case is this anchor
I will position this anchor at the center
I will palce it at the center of the screen
And let's start working on this
Now, I want this image
To be placed at the center
For that, here
There is 'Alignment' here
This is the ratio here
It goes from 0 to 1
So this is 0, and this is 1
So if I try 0.1 here
It goes to the left like so
And for this, we'll start with 0.0
Then it will move to the center like so
So for this, if we say 1
This is what happens
Then, if we say 0.5
It will be the center
And same thing here, 0.5
Then it is placed right at the center
That's where we start with
And let's change the color
Let's change it to black
This 'A' at the bottom is for Alpha
Or transparency, so 1 here means 100%
So let's reduce it down
To around 30%
Let's finish around here
And we will now add
Game Over with two buttons
So here
Go to Text
And place it here
So this is here, drag it in
And same thing here
We will work with the anchor a little
First, let's say 'Game Over'
Write it out like so
Let's give the font size around 150
Then this is what we get
And then, same thing here
Anchor at the center
And then with 0.0
This is what happens
And if we want this right at the center
Go to Alignment and say 0.5, 0.5
And it comes to the center
Here, I won't say this for the vertical position
So with this
Let's bring its Y position up a little
This is where we will place it
And let's add two buttons here
Button is right here
Add a button
Resize it a little
And we need some text in there
So that the button says something
So for the text, this is for 'Quit'
So let's write it out
Let's also resize it
I'll go with size 60
And let's change the button name to _Quit
Button_Quit
And let's make another
First, compile this and save
And do Ctrl D to duplicate
So place this over here
I am trying to do it fast
So this may not be the most aesthetic version, but you try yours nicely
So place it like so
These are at the top left now
So let's move the anchor to the center for all
Like so
Let's move everything to the center
This is how, even when we move it around
The anchor stays at the center
So that's what we do here
And this here should not be 'Quit'
We'll use 'Restart'
So let's change the text to 'Restart'
And if you want to change its color, click here
And change the background color
For Quit, we could use red
And for Restart
We could use blue, or something like that
You can also change the color of 'GameOver' here
Shall we go with yellow?
Then, in order to process this at the original Blueprint
Over at the top, we have Designer and Graph
Designer is where we work with the layouts
And Graph is where we do the visual coding
And we won't work on it here
We will make a class for this
So generally for UI
Widget designers start by making the widget
And with that, us programmers
Create a class and add it on
To further process it
So the other method is, this gets inherited with the existing Blueprint
And we create a component for it
To implement it here
But instead, we will make a variable at this side
And bind it together
So let's try this latter method together
So let's come over to GameOver Widget Header
And say 'public'
And let's write it out here
UPROPERTY
EditAnywhere
And then write 'class'
That's a button, so
So say UButton
We can actually see this
Here, it says Button
And to the top right, it says Open Button
So click on this
And we can see the class of that button
It says UButton here
So when you have trouble understanding
You can look for it like so
UButton, let's go with the pointer
And the name we use here must be the same as this name here
So say Button_Quit
And So you cannot add a space here
Everything should be together with no space
And then let's write it out
And we need to bind it
To bind, write 'meta' here
And you must add the parenthesis like this
And write 'BindWidget'
That's how you write it
And let's make another same thing
For not Quit but Restart
So that's how you do it
Save and let's go check
To check for the binding
Next to Hierarchy is 'Bind Widgets'
Now, it is not bound correctly
So we don't have anything bound
So this part is empty
So let's compile and take a look again
So this has been compiled
Over here, now it has a dropdown menu
And we get two successful ones
It's because they have the same name
If we are to change the name
This name at class and this name here
Then there will be an error
So it says the name is different, or that it cannot find it
So we need to set the name identically
So now when we compile, it works well
And now we will connect action to this button
Or rather, connect an event
In fact, if we are to do it on Blueprint
You can tick the box for Is Variable here
And at the bottom we see that event
I mean, you can see it even without Variable check
Anyways, you can click this, and if you want this to be clickable
Then you get this node over at Graph
So you can process it here
This is what works for Blueprint
Since we are going to process it a C++
We can come over here and process it
So if we press this
It calls a function
And after that call we can process it
So over here
We will connect a function
And to do so, we need something
We need a concept of 'start'
So over here
The starting function is this Construct
So we need to use this Construct function
It must be at the parent, inherited as virtual
It is being redefined for use
virtual void Native
We have this NativeConstruct
Which we can use to implement
So we connect our button here
And we need a function to call when the button is clicked
So we will create two more functions
Of course, as UFUNCTION
Meaning, these are also processed as delegates
So void OnClick, Quit
Copy everything, restart
Let's create these two functions
And over at this side
We will be connecting the button here
And here, we will be implementing the functions
So to connect thf button, at Button_Quit
We have a delegate named OnClicked
So it looks like this over here
It is hard to find, let's do it as it is
So here, after the period, AddDynamic
We can write it out as it says here
Add 'this' and connect the function like so
You must add that ampersand
You need to use the reference operator to pass over the address
So, we get the error because
This Header is not included to be added
So let's include it
So we include this button
You could write it this way
But I will do it this way
Here, we see that UMG here
It may not be a big error for now
Let me explain more after finishing this part
Let's set the Restart at our button
So this needs the restart
And we will ipmlement the function
It is a simple work to end the game
Here, we have UKismetSystemLibrary
And here we have the function QuitGame
And we first need World
And Player Control, second
And third, a sort of Type
How should we fill it in?
How should we end it?
And this, will it be a platform-dependent processing?
Are we going to ignore thoe on the platform?
That's the concept here
So for this fourth argument, for example
We have all the PlayStation games
And you do not quit the game right away
When you 'quit' during a game
It doesn't actually end the game
You just get out into the lobby screen
So will this ignore that?
This is asking that question
Same with Switch
So let's add one by one
Let's add GetWorld
And second, we are to add Player Controller
So at GetWorld, first player
GetFirstPlayerController
Bring this in like so
And that is EQuitPreference
So here it is
Let's add Quit
And then, next
Let's add false
It's because we haven't added the header
So let's add that header like so
Yes, you can add it at Kismet as well
So that's how we can use it
Quit is a simple task to implement
And for restart
We will reopen the level
So it's a reload
This will initialize everything
It destroys everything that has been loaded
And then it re-loads
So here, UGameplayStatics
Over here we have OpenLevel
We can open the level with this
So use GetWorld
And then our level name is
GameMap
So we can use that
So here, text
But this will be problematic if we change the name
So let's import the current level
The current level name, over here
We can use GetCurrentLevelName
So we can use it to bring it in
So here, let's first add the header
And this returns FString
So it returns something as a string
So let's say LevelName
So we add that levelname here
And we get an error
This is because
For OpenLevel
We need FName, not FString
This error was because of the wrong data type
We can just change it, so let's say FName
That's it, FName
And here in front of it
We add the value like so
This allows us to load the current level
So finally, we need this
Actual UI to show up
And that can be shown when Enemy
Bumps into Player
When 'you die' and 'I die' happen
So this means Player has been destroyed
So what we want to do is
We will make it stop
Stop!
Let's stop the game
Should we first show the UI?
The GameOver UI
Create it first and
Show it on the screen
That will be the first thing
And then we stop the game
Yes, let's process it like so
So we need soemthing to make that GameOver UI
So, the function to create UI is
This function is called CreateWidget
That's the function
And here, we need
At first we add World
getWorld, like so
And second, TSubClassOf
This is UClass here
So this goes in here
We made GameOver UI at Blueprint
So we will be adding that here
So let's make it over here
Should we say this?
GameOverUIFactory
So we can define that variable like so
Let's go over here and make it here
UPROPERTY
EditAnywhere
TSubclassOf, and then
Class
UGame
OverWidget
This is it
So this will create going through these
So let's take them all
And make it over here
So now that we made it, let's process it
But here, we don't have it
Because, this nees to be used now
But we haven't included UGameOverWidget
So there will be an error
So over here
Let's write this
Let's write GameOverWidget
Then there's no error
And let's add Auto UI like so
And we will take this to the screen
The fact that we made it
Doesn't automatically show it on the screen
So in order to do so
At UI, using the function AddToViewport
Let's show it to the screen
And we will stop the game
So, let's do this and
Let's do Live Coding to compile
Yes, it works
So we need to fill it in over at Enemy
This none is empty
So let's fill it in with GameOver
So over here
Let's run it
We have it now
But the problem is, we don't get the cursor
We don't have that mouse focus
So we need to process it
We'd like to show that mouse pointer
So we need this
Stop the game and show the mouse pointer
We need PlayerController for this
At GetWorld
Get GetFirstPlayerController
Let's hold onto this here
Let's say it as auto pc
So let's stop with this
And at PC, there's a function called SetPause
So let's add 'true' here
And we can simply not show this
Or, rather, we need to show the mouse pointer
SetShow
SetShowMouseCursor
So we can set this as 'true'
Then after GameOver
With the restart
We need to reverse this
We do not stop
We run it again
And we need to hide that mouse pointer again
So to do so
Let's do it when Player is born
So at BeginPlay, let's add false
Let's process it like so
Now, compile
So we get the cursor
Restart, and it's gone again
So it is working well
But it only begins after I click
So we need a bit of editing for that
At PlayerController
We have SetInputMode
So with this InputMode
At FInputMode we have these three
So for now, generally, it says GameAndUI
But if we say GameOnly
It won't accept any clicks
And for UIOnly
It will not get any input from the screen
So we can have more control using these
At first, we can go with GameOnly
For this, we can use the parenthesis
And with GameOver
At GameOver we can say UI Only
So we do that
And over here at processing GameOver
It's UI Only
So by setting this up
It will control things better
So compile
And run
So even without the click, I can move it right away
It works
And after it is destroyed
It pauses and we get the UI
And no input at the game
And with Restart, we can press the key right away to move
That's how it processes it
That was on C++ based shooter game production
Thank you
Let's summarize what we've learned this chapter
Processing Collision Individual Collision Response Setup NotifyActorBeginOverlap() function detects partial collision
Calls OnComponentBeginOverlap delegate Copy entire parameter + paste and delete the comma between data type and variable
MeshComp -> SetCollisionEnabled() function declared BoxComp -> SetGenerateOverLapEvent() function declared
SetCollisionResponseToChannel() function to set individual channel
Set as Preset Creating collision response setting every time for object is not efficient
Create New Profile, create Player, Bullet, Enemy at Collision Presets
BoxComp -> function SetCollisionProfileName() declared Set the right collision Profile for each class
GameOver UI Production At Blueprint folder, select Widget Blueprint at User Interface
ALL CLASSES -> select GameOverWidget Drag and drop Canvas Panel to set up UI screen
Even with the resolution change, central anchor makes sure everything is centered Create variables and implement using bind
Event connection for buttons To connect button, declare function NativeConstruct() At OnClicked delegate, connect existing functions using AddDynamic
Quit button : UKismetSystemLibrary::QuitGame Restart button : OpenLevel at GamePlayStatics
To creat UI, declare CreateWidget To show it on screen, declare AddtoVieport
The End