﻿1
00:00:04,310 --> 00:00:05,510
‫Hello and welcome.

2
00:00:05,510 --> 00:00:12,560
‫In this lecture, we're going to be attaching our goggles statue and switching off physics simulation

3
00:00:12,560 --> 00:00:15,830
‫when we stick it in to the door alcove.

4
00:00:15,830 --> 00:00:16,850
‫So there you go.

5
00:00:16,850 --> 00:00:22,580
‫It's gone down with the door and we're able to access the crypt beneath.

6
00:00:22,580 --> 00:00:24,620
‫Let's dive in and see how it's done.

7
00:00:25,390 --> 00:00:31,450
‫So in the case where we do have an actor inside our trigger components, the acceptable actor, we want

8
00:00:31,450 --> 00:00:38,710
‫that actor to stop simulating physics, get attached to our trigger component and move with us.

9
00:00:39,160 --> 00:00:41,160
‫How can we go about doing this?

10
00:00:41,170 --> 00:00:44,590
‫Well, the functions we're going to need are the following.

11
00:00:44,590 --> 00:00:48,610
‫We're going to need the actor's function called attach to component.

12
00:00:48,610 --> 00:00:55,810
‫This allows us to take an actor and attach its root component to another component, which will mean

13
00:00:55,810 --> 00:01:00,820
‫that the actor then moves with the component that's been supplied.

14
00:01:01,220 --> 00:01:07,470
‫Then the other thing we need to do to stop it simulating physics is on the primitive component itself.

15
00:01:07,480 --> 00:01:09,760
‫There is a function called set simulate physics.

16
00:01:09,760 --> 00:01:16,840
‫It takes in a boolean so you can set it to false so that it stops and it basically will stop being detached.

17
00:01:16,870 --> 00:01:19,090
‫Well, we've got one piece of the puzzle.

18
00:01:19,090 --> 00:01:22,670
‫We already have hold of the actor that is the acceptable actor.

19
00:01:22,690 --> 00:01:29,260
‫Now we need to get the root component of that actor and see whether it is a you primitive component,

20
00:01:29,260 --> 00:01:34,060
‫because it's not a given that an actor has a primitive component at its root.

21
00:01:34,120 --> 00:01:36,760
‫It just has to have a scene component at its root.

22
00:01:37,120 --> 00:01:43,420
‫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

23
00:01:43,420 --> 00:01:48,880
‫where we know it's not a null pointer to arrow get root component.

24
00:01:48,880 --> 00:01:56,150
‫And if we have a look at the return type for this, we can see that it is a U seen component.

25
00:01:56,170 --> 00:02:03,400
‫Now that's a parent to the you primitive component, but it doesn't mean that this type is actually

26
00:02:03,400 --> 00:02:04,780
‫a you primitive component.

27
00:02:04,900 --> 00:02:07,170
‫So what do we do in this case?

28
00:02:07,180 --> 00:02:13,480
‫Well, we have to find out whether we've got a primitive component and we can use some a function called

29
00:02:13,480 --> 00:02:14,390
‫cast.

30
00:02:14,410 --> 00:02:18,010
‫Again, it's one of these functions that takes compile time parameters.

31
00:02:18,010 --> 00:02:21,940
‫So we use the angle brackets and we can give it that.

32
00:02:21,940 --> 00:02:30,400
‫We want to cast the pointer to a you primitive component, close the angle brackets and then in the

33
00:02:30,400 --> 00:02:37,450
‫actual runtime parameters, the runtime arguments we do parentheses and we include this actor get root

34
00:02:37,450 --> 00:02:38,290
‫component.

35
00:02:38,290 --> 00:02:44,770
‫So what it's doing is it's going to check whether this you've seen component is actually a you primitive

36
00:02:44,770 --> 00:02:51,580
‫component and the output will be a pointer to that you primitive component or it will be a null pointer.

37
00:02:51,580 --> 00:02:55,600
‫If in fact we had a scene component that wasn't a primitive component.

38
00:02:55,600 --> 00:02:58,180
‫So let's store that component pointer.

39
00:02:58,510 --> 00:03:03,850
‫So it's going to be a primitive component pointer, which we're just going to call the component.

40
00:03:04,510 --> 00:03:08,950
‫And then before we use this, we need to make sure we check whether it's null.

41
00:03:08,950 --> 00:03:17,860
‫So we're going to say if component not equal null pointer, then we can do something with that component

42
00:03:17,860 --> 00:03:18,570
‫pointer.

43
00:03:18,580 --> 00:03:22,630
‫So I'd like to challenge you to try this out for yourself, setting up the attachment.

44
00:03:22,630 --> 00:03:28,360
‫You're going to open the docs in the links, try and read it, make sense of what is saying you can

45
00:03:28,360 --> 00:03:28,840
‫do.

46
00:03:28,990 --> 00:03:31,660
‫Use the actor to attach the current component.

47
00:03:31,660 --> 00:03:40,930
‫You can get hold to a pointer of the current object using this this key word in C++.

48
00:03:40,930 --> 00:03:47,560
‫Then for the second arguments that function, you will need to use the F attachment transform rules

49
00:03:47,560 --> 00:03:50,530
‫colon colon keep world transform.

50
00:03:50,530 --> 00:03:54,340
‫You can have a look in the documentation to kind of see what that means if you want to.

51
00:03:54,610 --> 00:04:00,730
‫And then finally use the component that we've cast to disable physics again using the documentation

52
00:04:00,760 --> 00:04:03,640
‫to see which function and what parameters.

53
00:04:03,640 --> 00:04:06,580
‫Arguments to put in pause video and have a go.

54
00:04:09,700 --> 00:04:10,720
‫Hey, welcome back.

55
00:04:10,750 --> 00:04:13,870
‫So, first of all, I'm going to use the components to disable physics.

56
00:04:13,870 --> 00:04:19,750
‫So it's going to be components arrow set, simulate physics.

57
00:04:20,700 --> 00:04:21,540
‫False.

58
00:04:21,570 --> 00:04:26,970
‫Looks like I've got a semicolon missing at the end of my cast line, so let's put that in there as well.

59
00:04:27,300 --> 00:04:29,970
‫And then we're going to attach the actor.

60
00:04:29,970 --> 00:04:35,460
‫So it's going to be actor arrow attach to component.

61
00:04:36,120 --> 00:04:38,850
‫The component we're attaching it to is this.

62
00:04:38,850 --> 00:04:41,910
‫So let's have a look at this second parameter.

63
00:04:41,910 --> 00:04:47,310
‫We've got this F attached transform rules type, which is obviously a struct and it basically tells

64
00:04:47,310 --> 00:04:50,220
‫us how we should handle the attachment.

65
00:04:50,220 --> 00:04:53,340
‫There's a couple of prebuilt ones in here.

66
00:04:53,340 --> 00:04:59,190
‫We've got the heap relative transform, which would essentially move our object when we attach it.

67
00:04:59,190 --> 00:05:00,330
‫So we don't want that.

68
00:05:00,750 --> 00:05:03,510
‫What we want is keep world transform.

69
00:05:03,510 --> 00:05:04,950
‫So we're going to use that.

70
00:05:05,490 --> 00:05:14,370
‫So it's F attachment transform rules colon, colon keep world transform, put a semicolon at the end

71
00:05:14,370 --> 00:05:16,470
‫of that line and recompile.

72
00:05:16,500 --> 00:05:17,100
‫So that's done.

73
00:05:17,100 --> 00:05:25,410
‫Let's hop into the editor, go ahead and hit play, grab our gargoyle and stick him into the alcove.

74
00:05:25,830 --> 00:05:33,000
‫And you can see he has gone down with the floor and the floor has gone all the way through allowing

75
00:05:33,000 --> 00:05:36,210
‫us access to our crypt.

76
00:05:36,210 --> 00:05:37,800
‫Fantastic stuff.

77
00:05:37,800 --> 00:05:45,270
‫So in this lecture we've learnt about attachment between actors and components and how we can cast to

78
00:05:45,270 --> 00:05:47,130
‫convert the type.

79
00:05:47,130 --> 00:05:51,000
‫If the type is convertible, I'll see you in the next lecture.

