﻿1
00:00:04,390 --> 00:00:05,590
‫Hello and welcome.

2
00:00:05,590 --> 00:00:10,180
‫In this lecture, we're going to be adding a tag to an object that's currently being grabbed.

3
00:00:10,180 --> 00:00:15,670
‫So if I grab this gargoyle f eight out and have a look at the Gargoyle statue, you can see it now has

4
00:00:15,670 --> 00:00:17,740
‫this grabbed tag attached.

5
00:00:17,740 --> 00:00:25,210
‫If I go ahead and release the gargoyle and have a look at it again, you can see the tag goes away.

6
00:00:25,210 --> 00:00:30,310
‫So this will communicate to other gameplay things in our scene that the gargoyle is currently being

7
00:00:30,310 --> 00:00:33,220
‫held and that it shouldn't be snatched away.

8
00:00:33,220 --> 00:00:35,440
‫Let's dive in and see how to implement this.

9
00:00:36,430 --> 00:00:42,670
‫So at the moment when we drop the gargoyle in to the trigger area, what happens is the trigger area

10
00:00:42,670 --> 00:00:47,620
‫kind of snatches the gargoyle away and doesn't wait for us to finish letting go.

11
00:00:47,650 --> 00:00:53,650
‫And this is because the trigger area has no notion of the fact that that gargoyle is being held by a

12
00:00:53,650 --> 00:00:54,430
‫grabber.

13
00:00:54,790 --> 00:01:02,050
‫So to do that, to give the to communicate to the trigger components that we have got some kind of hold

14
00:01:02,050 --> 00:01:08,380
‫on the gargoyle, we're again going to use tags, except this time we're going to add and remove them

15
00:01:08,380 --> 00:01:12,070
‫programmatically and we're going to be doing this over in the grabber.

16
00:01:12,100 --> 00:01:18,880
‫CP So let's open that up in the Visual Studio code and have a look at our grab function where currently

17
00:01:18,880 --> 00:01:24,790
‫what we're doing with the component that we hit is that we are simply going ahead and waking all the

18
00:01:24,790 --> 00:01:25,630
‫rigid bodies.

19
00:01:25,720 --> 00:01:29,440
‫So what we want to do now is add a new tag.

20
00:01:29,440 --> 00:01:30,130
‫How do we do that?

21
00:01:30,130 --> 00:01:32,800
‫Well, first of all, we need to get hold of the actor in question.

22
00:01:32,800 --> 00:01:43,150
‫So we should do hit result dot get actor and then using that actor pointer so arrow we can look for

23
00:01:43,180 --> 00:01:44,020
‫tags.

24
00:01:44,050 --> 00:01:46,930
‫Now tags is a property that is a t array.

25
00:01:46,930 --> 00:01:50,380
‫So we've seen t arrays, that's a t array of f names.

26
00:01:50,680 --> 00:01:56,680
‫So we need to be able to manipulate this tray to add and remove tags from it.

27
00:01:56,680 --> 00:02:00,910
‫So let's go back to the tray and see what's available to us.

28
00:02:01,210 --> 00:02:07,780
‫If we search for ADD, you can see that there is a bunch of functionality where you can pass in the

29
00:02:07,780 --> 00:02:15,520
‫element type, which in our case is an F name and it adds a new item to the end of the array and does

30
00:02:15,670 --> 00:02:19,480
‫all the jobs that it needs to do to make sure that you have space for it.

31
00:02:19,780 --> 00:02:26,350
‫If you search for remove, there's a whole bunch of things that mention removing, but only a few methods

32
00:02:26,350 --> 00:02:28,810
‫that actually have the name remove.

33
00:02:28,810 --> 00:02:32,560
‫And you can see it removes many instances of an item as there are in the array.

34
00:02:32,560 --> 00:02:33,550
‫So what's that saying?

35
00:02:33,550 --> 00:02:41,440
‫It's saying if it has that item in the array, it will remove all of the instances of that item from

36
00:02:41,440 --> 00:02:41,800
‫the array.

37
00:02:41,800 --> 00:02:46,720
‫So if you put in multiple tags with the same name, it would remove them all.

38
00:02:46,720 --> 00:02:52,690
‫Whereas if you look further down there is a remove at and this would remove an element, a specific

39
00:02:52,690 --> 00:02:53,470
‫index.

40
00:02:53,470 --> 00:03:00,700
‫Now we definitely want the former rather than the latter because we want to remove by the tag name which

41
00:03:00,700 --> 00:03:02,440
‫we're going to just call grabbed.

42
00:03:02,440 --> 00:03:08,350
‫So let's start with adding, we'll go back into Visual Studio code and we've got this tags array.

43
00:03:08,350 --> 00:03:14,380
‫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.

44
00:03:14,470 --> 00:03:19,030
‫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

45
00:03:19,030 --> 00:03:21,520
‫called grabbed like so.

46
00:03:21,520 --> 00:03:29,170
‫So this should when we grab the object, add a tag to it that says it has been grabbed, let's go ahead

47
00:03:29,170 --> 00:03:30,610
‫and compile this and check.

48
00:03:30,610 --> 00:03:37,360
‫Once that's done, let's go ahead and hit play and try and pick up the gargoyle like so then I'm going

49
00:03:37,360 --> 00:03:46,360
‫to hit F eight to possess and we should be able to select our gargoyle actor, scroll down and have

50
00:03:46,360 --> 00:03:48,460
‫a look at its actor tags.

51
00:03:48,460 --> 00:03:50,720
‫So that's in the actors section under advanced.

52
00:03:50,740 --> 00:03:51,910
‫We can have a look at the tags.

53
00:03:51,910 --> 00:03:53,560
‫We can see there are three tags there.

54
00:03:53,560 --> 00:03:59,470
‫Currently we have got unlock one and then grabbed and then grabbed again because we didn't remove it.

55
00:03:59,470 --> 00:04:04,690
‫We actually if we grab it twice by accident, which I think I must have done, then it adds the tag

56
00:04:04,690 --> 00:04:05,620
‫twice.

57
00:04:05,620 --> 00:04:10,660
‫So I'd like you to remove the tag when we release the actor.

58
00:04:10,660 --> 00:04:16,390
‫So you're going to get hold of the actor in release remembering that you can use get owner to get hold

59
00:04:16,390 --> 00:04:17,230
‫of the owning actor.

60
00:04:17,230 --> 00:04:24,100
‫If you've got hold of a component already, you can get the tag array from that actor and then you can

61
00:04:24,100 --> 00:04:28,210
‫call remove on it with the tag that you want to remove from the array.

62
00:04:28,210 --> 00:04:31,300
‫And finally go ahead and test it out, see if it works.

63
00:04:31,300 --> 00:04:33,220
‫Pause the video and have a go.

64
00:04:36,230 --> 00:04:36,520
‫Okay.

65
00:04:36,520 --> 00:04:37,600
‫Welcome back.

66
00:04:37,720 --> 00:04:38,230
‫Right.

67
00:04:38,230 --> 00:04:44,920
‫So I'm going to stop playing, go back into Visual Studio code and we're going to go in to the release

68
00:04:44,920 --> 00:04:48,760
‫where we've got this get grabbed component and not equal to null.

69
00:04:48,760 --> 00:04:49,900
‫And then we're releasing things.

70
00:04:49,900 --> 00:04:57,010
‫Well, we need to get the ground component, but we need to get owner of that grabbed component as well.

71
00:04:57,010 --> 00:05:03,940
‫So arrow from the get go component, get owner to keep this line short, I'm going to put it in a variable.

72
00:05:03,970 --> 00:05:11,770
‫A actor grabbed actor equals handle get grabbed component get owner.

73
00:05:12,520 --> 00:05:22,180
‫Then with that grabbed actor, we can do grabbed actor arrow tags and then we're going to do tags or

74
00:05:22,240 --> 00:05:30,280
‫remove and we're going to remove, grabbed, make sure that you have the exact same string for the two

75
00:05:31,000 --> 00:05:33,490
‫semicolon at the end of the line and let's recompile.

76
00:05:33,490 --> 00:05:37,510
‫So now if I hit play near the gargoyle, I'll go and pick him up.

77
00:05:37,960 --> 00:05:39,520
‫Hit F eight.

78
00:05:40,000 --> 00:05:42,490
‫Let's have a look at the gargoyle, see what tags we've got.

79
00:05:42,490 --> 00:05:43,840
‫We've got the grabbed tag.

80
00:05:43,840 --> 00:05:46,020
‫Only one of them this time, which is good.

81
00:05:46,030 --> 00:05:55,330
‫Now if we repossess and click in and we drop release, then we can f eight again, select that gargoyle

82
00:05:55,330 --> 00:05:59,950
‫statue, have a look at tags, and sure enough, the grab tag has gone away.

83
00:05:59,950 --> 00:06:06,160
‫So this will give us an excellent mechanism to communicate to other components in the world that this

84
00:06:06,160 --> 00:06:07,810
‫gargoyle, hey, it's mine.

85
00:06:07,810 --> 00:06:09,070
‫It's currently grabbed.

86
00:06:09,430 --> 00:06:14,560
‫Don't try and take it away from me and lock it into any kind of receiving triggers.

87
00:06:14,800 --> 00:06:16,630
‫And that's what we're going to do in the next lecture.

88
00:06:16,630 --> 00:06:17,650
‫So I'll see you there.

