‫Hello and welcome.
‫In this lecture, we're going to be attaching our goggles statue and switching off physics simulation
‫when we stick it in to the door alcove.
‫So there you go.
‫It's gone down with the door and we're able to access the crypt beneath.
‫Let's dive in and see how it's done.
‫So in the case where we do have an actor inside our trigger components, the acceptable actor, we want
‫that actor to stop simulating physics, get attached to our trigger component and move with us.
‫How can we go about doing this?
‫Well, the functions we're going to need are the following.
‫We're going to need the actor's function called attach to component.
‫This allows us to take an actor and attach its root component to another component, which will mean
‫that the actor then moves with the component that's been supplied.
‫Then the other thing we need to do to stop it simulating physics is on the primitive component itself.
‫There is a function called set simulate physics.
‫It takes in a boolean so you can set it to false so that it stops and it basically will stop being detached.
‫Well, we've got one piece of the puzzle.
‫We already have hold of the actor that is the acceptable actor.
‫Now we need to get the root component of that actor and see whether it is a you primitive component,
‫because it's not a given that an actor has a primitive component at its root.
‫It just has to have a scene component at its root.
‫So the way we can do this is we can go to the actor point and make sure we're doing this in the if statement
‫where we know it's not a null pointer to arrow get root component.
‫And if we have a look at the return type for this, we can see that it is a U seen component.
‫Now that's a parent to the you primitive component, but it doesn't mean that this type is actually
‫a you primitive component.
‫So what do we do in this case?
‫Well, we have to find out whether we've got a primitive component and we can use some a function called
‫cast.
‫Again, it's one of these functions that takes compile time parameters.
‫So we use the angle brackets and we can give it that.
‫We want to cast the pointer to a you primitive component, close the angle brackets and then in the
‫actual runtime parameters, the runtime arguments we do parentheses and we include this actor get root
‫component.
‫So what it's doing is it's going to check whether this you've seen component is actually a you primitive
‫component and the output will be a pointer to that you primitive component or it will be a null pointer.
‫If in fact we had a scene component that wasn't a primitive component.
‫So let's store that component pointer.
‫So it's going to be a primitive component pointer, which we're just going to call the component.
‫And then before we use this, we need to make sure we check whether it's null.
‫So we're going to say if component not equal null pointer, then we can do something with that component
‫pointer.
‫So I'd like to challenge you to try this out for yourself, setting up the attachment.
‫You're going to open the docs in the links, try and read it, make sense of what is saying you can
‫do.
‫Use the actor to attach the current component.
‫You can get hold to a pointer of the current object using this this key word in C++.
‫Then for the second arguments that function, you will need to use the F attachment transform rules
‫colon colon keep world transform.
‫You can have a look in the documentation to kind of see what that means if you want to.
‫And then finally use the component that we've cast to disable physics again using the documentation
‫to see which function and what parameters.
‫Arguments to put in pause video and have a go.
‫Hey, welcome back.
‫So, first of all, I'm going to use the components to disable physics.
‫So it's going to be components arrow set, simulate physics.
‫False.
‫Looks like I've got a semicolon missing at the end of my cast line, so let's put that in there as well.
‫And then we're going to attach the actor.
‫So it's going to be actor arrow attach to component.
‫The component we're attaching it to is this.
‫So let's have a look at this second parameter.
‫We've got this F attached transform rules type, which is obviously a struct and it basically tells
‫us how we should handle the attachment.
‫There's a couple of prebuilt ones in here.
‫We've got the heap relative transform, which would essentially move our object when we attach it.
‫So we don't want that.
‫What we want is keep world transform.
‫So we're going to use that.
‫So it's F attachment transform rules colon, colon keep world transform, put a semicolon at the end
‫of that line and recompile.
‫So that's done.
‫Let's hop into the editor, go ahead and hit play, grab our gargoyle and stick him into the alcove.
‫And you can see he has gone down with the floor and the floor has gone all the way through allowing
‫us access to our crypt.
‫Fantastic stuff.
‫So in this lecture we've learnt about attachment between actors and components and how we can cast to
‫convert the type.
‫If the type is convertible, I'll see you in the next lecture.