‫Hello and welcome.
‫In this lecture, we're going to be adding a tag to an object that's currently being grabbed.
‫So if I grab this gargoyle f eight out and have a look at the Gargoyle statue, you can see it now has
‫this grabbed tag attached.
‫If I go ahead and release the gargoyle and have a look at it again, you can see the tag goes away.
‫So this will communicate to other gameplay things in our scene that the gargoyle is currently being
‫held and that it shouldn't be snatched away.
‫Let's dive in and see how to implement this.
‫So at the moment when we drop the gargoyle in to the trigger area, what happens is the trigger area
‫kind of snatches the gargoyle away and doesn't wait for us to finish letting go.
‫And this is because the trigger area has no notion of the fact that that gargoyle is being held by a
‫grabber.
‫So to do that, to give the to communicate to the trigger components that we have got some kind of hold
‫on the gargoyle, we're again going to use tags, except this time we're going to add and remove them
‫programmatically and we're going to be doing this over in the grabber.
‫CP So let's open that up in the Visual Studio code and have a look at our grab function where currently
‫what we're doing with the component that we hit is that we are simply going ahead and waking all the
‫rigid bodies.
‫So what we want to do now is add a new tag.
‫How do we do that?
‫Well, first of all, we need to get hold of the actor in question.
‫So we should do hit result dot get actor and then using that actor pointer so arrow we can look for
‫tags.
‫Now tags is a property that is a t array.
‫So we've seen t arrays, that's a t array of f names.
‫So we need to be able to manipulate this tray to add and remove tags from it.
‫So let's go back to the tray and see what's available to us.
‫If we search for ADD, you can see that there is a bunch of functionality where you can pass in the
‫element type, which in our case is an F name and it adds a new item to the end of the array and does
‫all the jobs that it needs to do to make sure that you have space for it.
‫If you search for remove, there's a whole bunch of things that mention removing, but only a few methods
‫that actually have the name remove.
‫And you can see it removes many instances of an item as there are in the array.
‫So what's that saying?
‫It's saying if it has that item in the array, it will remove all of the instances of that item from
‫the array.
‫So if you put in multiple tags with the same name, it would remove them all.
‫Whereas if you look further down there is a remove at and this would remove an element, a specific
‫index.
‫Now we definitely want the former rather than the latter because we want to remove by the tag name which
‫we're going to just call grabbed.
‫So let's start with adding, we'll go back into Visual Studio code and we've got this tags array.
‫So what we can do with it is we can simply do a dot because it's not a pointer, it's the actual array.
‫Then we're going to call add and then we're going to add an F name which we can just use a string for
‫called grabbed like so.
‫So this should when we grab the object, add a tag to it that says it has been grabbed, let's go ahead
‫and compile this and check.
‫Once that's done, let's go ahead and hit play and try and pick up the gargoyle like so then I'm going
‫to hit F eight to possess and we should be able to select our gargoyle actor, scroll down and have
‫a look at its actor tags.
‫So that's in the actors section under advanced.
‫We can have a look at the tags.
‫We can see there are three tags there.
‫Currently we have got unlock one and then grabbed and then grabbed again because we didn't remove it.
‫We actually if we grab it twice by accident, which I think I must have done, then it adds the tag
‫twice.
‫So I'd like you to remove the tag when we release the actor.
‫So you're going to get hold of the actor in release remembering that you can use get owner to get hold
‫of the owning actor.
‫If you've got hold of a component already, you can get the tag array from that actor and then you can
‫call remove on it with the tag that you want to remove from the array.
‫And finally go ahead and test it out, see if it works.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫Right.
‫So I'm going to stop playing, go back into Visual Studio code and we're going to go in to the release
‫where we've got this get grabbed component and not equal to null.
‫And then we're releasing things.
‫Well, we need to get the ground component, but we need to get owner of that grabbed component as well.
‫So arrow from the get go component, get owner to keep this line short, I'm going to put it in a variable.
‫A actor grabbed actor equals handle get grabbed component get owner.
‫Then with that grabbed actor, we can do grabbed actor arrow tags and then we're going to do tags or
‫remove and we're going to remove, grabbed, make sure that you have the exact same string for the two
‫semicolon at the end of the line and let's recompile.
‫So now if I hit play near the gargoyle, I'll go and pick him up.
‫Hit F eight.
‫Let's have a look at the gargoyle, see what tags we've got.
‫We've got the grabbed tag.
‫Only one of them this time, which is good.
‫Now if we repossess and click in and we drop release, then we can f eight again, select that gargoyle
‫statue, have a look at tags, and sure enough, the grab tag has gone away.
‫So this will give us an excellent mechanism to communicate to other components in the world that this
‫gargoyle, hey, it's mine.
‫It's currently grabbed.
‫Don't try and take it away from me and lock it into any kind of receiving triggers.
‫And that's what we're going to do in the next lecture.
‫So I'll see you there.