‫Hello and welcome.
‫In this lecture, we're going to be creating a new component in C++, this trigger box, which will
‫report to us when we step inside the alcove or we place any object in the alcove.
‫You can see we're getting a little blueprint message up in the top left hand corner.
‫And to do that, we're going to have to understand how overlaps and blocking and different collision
‫responses behave in Unreal.
‫Let's dive in and find out.
‫Now we've already become familiar with how trace channels work.
‫We know that you can have trace responses on the different objects in our scene, such as this shrub.
‫Here, you can see that it has a ignore response to weapon traces, but it does block visibility traces.
‫Then there's this bulletproof glass example.
‫It blocks weapons but allows visibility through and a brick wall which blocks both.
‫So you can see how this system works with trace channels.
‫Now, what happens if we're trying to decide which objects can overlap with each other, which ones
‫pass through, which ones block each other?
‫That can get a little bit more complicated.
‫We saw this already when we tried to get the gargoyle to overlap with our pawn.
‫Now this is how it works.
‫Essentially, we use these object types.
‫Each object can belong to can be a particular object type.
‫And this is different to the kind of type system in C++.
‫These are collision types.
‫So you might have object A and object B and in their settings, if we go and have a look at the settings
‫on our gargoyle, for example, you can see that they have their own object type.
‫This one is a world static object, but then further down they have their responses to other types of
‫objects as well.
‫So you can see that this object will block other world statics, it will block other world dynamics,
‫it will overlap the pawn types, it will block physics bodies and pretty much block every other type.
‫And obviously the pawn itself if we go and find our BP player.
‫And look in its capsule component, look at the details and scroll on down to where it's got a collision
‫preset.
‫If we can expand out the Pawn Collision preset, we can't edit it, but we can see what it's doing.
‫And you can see that it has its own response to world static.
‫So its response to the world static would be to block it.
‫So we've actually got two different options here.
‫The pawn is saying I block world statics, but the gargoyle is saying I overlap pawns.
‫So what should happen?
‫Well, this is where this table comes in and I've got a link to this blog post if you want to read it
‫in full in the lecture resources.
‫So you can see that it takes the least blocking interaction between the two.
‫So if the object A was the pawn and we're saying, hey, I should block that gargoyle, but the gargoyles
‫object B and it's saying, hey, I should overlap that pawn.
‫So it's going to take the least blocking of those two and it's going to overlap.
‫So it does mean that if you want two things to block each other, they both need to agree that that's
‫what they want to do.
‫So let's look at another example here.
‫We've got the player which is of object type pawn, and it's object response to other pawns is to block
‫them and world static objects is to block them.
‫The brick wall is a world static object.
‫It can block pawns and block world static.
‫So these two would agree with each other.
‫Now the shrub is also world static, but it overlaps pawns.
‫It's very much like our gargoyle, but it blocks world statics.
‫So if you go down and have a look at what would happen is the pawn would try and travel through the
‫bush and it could because it takes the least blocking option, which is overlap and it generates an
‫overlap event which we can hook into in code or blueprint, whereas it won't be able to pass through
‫the brick wall and it generates a hit event again, something that we can hook onto in Blueprint or
‫C++.
‫So why do I go into all of this depth?
‫Because what I want to do is put an object that we is basically invisible inside this wall that allows
‫us to put the gargoyle in here and we get an event when that happens.
‫So the gargoyle will prop up an event and say, Hey, I've got something overlapping with me.
‫So why is all of this important?
‫Because I want to put an object that's invisible but will overlap with the gargoyle and let us know
‫about that fact.
‫We can then query it from C++ or we can get events in Blueprint either way.
‫And the way we're going to do this is, first of all, create a blueprint from this dungeon wall.
‫So I'm going to click the blueprint button in the details pane, create a new subclass, and I'm going
‫to name it beep, underscore secret wall and we're going to hit select to create it and a docket to
‫our main window and it's got a mover on it.
‫What I also want to add in here is essentially a component which is called a box collision.
‫So if we click on a box collision, you can see it's completely invisible.
‫It just gives you some box extents which we can change, we can make them larger so that anywhere we
‫place the gargoyle in this box, it's going to accept it.
‫And we can see that it has got collision options down here.
‫We've got an overlap all dynamic as the default, but as the default preset.
‫But if we hit custom, you can see we can change the object types and we can change how it responds
‫to different things in here.
‫And I think most importantly, as you can see, it's set up to overlap with most object types, which
‫means that even if they're not set to overlap with world dynamic, it's going to overlap.
‫It's not going to block anything.
‫It's going to let us position the gargoyle in here.
‫So I'm going to go and delete that component from the scene, because what I want to do is create a
‫new component in C++ based off of that box collision.
‫Now I just want to show you that with this box, if we set it back to the default preset it was on,
‫which was overlap all dynamic I believe and we check or as is already checked actually generate overlap
‫events is already checked.
‫Then we can go over into our event graph and we can right click in here and look for overlap.
‫And right at the top you can see an add on component begin overlap for the box.
‫So if we click that and actually let's rename the box component to trigger area like.
‫So then basically if we overlap with the trigger area, we're going to get a list of properties of the
‫thing that's overlapping with us so we could take the.
‫It's overlapping.
‫We could get its name.
‫So get display name is the name of the node.
‫And then we could take that and print the result string and hook that up to the execution pin and we
‫can go ahead and hit play.
‫And if we walk up to the area, you can see that it's saying the beep player is the thing overlapping
‫it.
‫Now I can't see that area because it's so dark.
‫So I'm just going to go to the secret wall again, a beep and I'm going to add in a spot light component,
‫which I'm going to place in this little alcove, rotating it to face down and illuminating the space
‫where we want the object.
‫Now in the scene, we can see it very clearly.
‫So let's go ahead and hit play and we can walk up to that alcove.
‫If we overlap it, it says there's the beep player overlapping and we can go and grab our gargoyle from
‫this cell using our newly minted grabber, and we can take that gargoyle and place it in this area.
‫However, it doesn't seem to be generating any overlap events, and that's because just like we need,
‫there's two parties to the collision.
‫There's also two parties to generating overlap events.
‫So just because we have it enabled on that box component doesn't mean that the gargoyle moving into
‫it is actually going to alert us to any overlap events.
‫So what we have to do is we have to go to the gargoyle and check it, generate overlap events as well.
‫So then the overlap events should happen.
‫Let's go and pick up the gargoyle, take him over to the alcove and stick him in.
‫And now we are getting an event coming up.
‫When that happens, the Gargoyle statue is indeed being registered.
‫Now, I don't want to be using blueprint events in this particular case.
‫So what I want to do is take our trigger area component and actually turn that into some a C++ component
‫that can evaluate whether it's got the Gargoyle statue at once or not already in it.
‫The way we're going to do this is we're going to go to the add components, create a new C++ component.
‫And as the parent class, instead of choosing active component or scene component, we're going to go
‫to all classes and we're going to search for the box component instead.
‫And you can see the shape components, box components, the one we want and we can go ahead and hit
‫next.
‫So I'd like to challenge you to create this component now that I've shown you how to set the parent
‫class.
‫So you're going to name it trigger components and you're going to have to copy some things from the
‫other components we've created because it's not set up in the same way.
‫Seeing as we're deriving from a different parent, you're going to have to copy the you class line.
‫That whole line is basically empty on the trigger component as you will create it.
‫So copy that from either your grabber or your mover, and otherwise you won't be able to add your components
‫in to your blueprints.
‫So then you should use this new trigger components to replace our current box component and print something
‫from Begin Play.
‫Again, it big in play won't be set up automatically for you, so you're going to have to copy from
‫the header file and C++ file of our other components in order to set it up.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So I'm going to call it the trigger component.
‫All one word and hit to create class.
‫So as predicted you class line is got nothing inside the parentheses and if we go and have a look at
‫our editor and go to the BP secret wall, try to add this component and search for trigger, you can
‫see nothing comes up.
‫And the reason for this is if we went over to our grab a dot H and had a look at its use class line,
‫you can see that there's a bit in here that says blueprint spawn able component.
‫So crucially, we need to copy this.
‫It also has a class group.
‫We might as well copy the whole thing because this allows us to create this component in blueprint so
‫we can go and paste this as the class line for the trigger component.
‫And then the other thing, if we go to grab, you can see it's got big in play, it's within a protected
‫section and we can just copy the definition of that begin play function, copy it over into our trigger
‫component and put it as it was in the grabber, just underneath the generated body.
‫Then we can go into our grab a CP and see how big in play was defined.
‫In here you can see that it has this cool to super big in play that is actually important.
‫So we're going to copy that, go over into a trigger component.
‫CP And we're going to change the you grab a colon colon to you trigger component, begin play.
‫And then in here we can put in our you log and we're just going to write a simple message such as trigger
‫component alive and we'll go ahead and compile.
‫This may take a little while, seeing as we've made some fairly significant changes to our header file.
‫And once that's done, we can go into our BP secret wall, go to add and search for trigger.
‫And in here you can see we've got that trigger component.
‫We can now add that in.
‫We can remove our trigger area that we've set up previously.
‫Just go ahead and delete that and check yet we want to delete it.
‫It's going to basically invalidate this event that we created and we can check that the collisions are
‫set up as we want on the trigger if we're going to have a look.
‫Yet, it's set to overlap all dynamic and to generate overlap events.
‫And finally, what we need to replace is this event here where we're going to select our trigger right
‫click and go to unfurl the add event for trigger collision and add on on component begin overlap.
‫That's what we were using before.
‫Hook up the active pin and hook up the execution pin to head over to the dungeon level.
‫Go and pick up the gargoyle, try and stick it in the alcove and we notice that's not working.
‫So now we've got that trigger set up.
‫Let's go to the viewport and you can see that actually the trigger isn't been it hasn't been made big
‫enough.
‫We haven't positioned it correctly.
‫So let's go and position it in the center of the alcove and let's increase the box extent properties
‫so that we catch whatever we've put inside this alcove area.
‫Doesn't matter if it is a little bit bigger and gives us a safety margin and we can go into the dungeon,
‫hit play and then step into the alcove.
‫And sure enough, it detects that the BP player has walked in to that alcove.
‫Great stuff.
‫In this lecture, we've learned all about object types and object type responses, and we've used that
‫to set up this trigger component.
‫I'll see you in the next lecture.