Unreal Engine Crash

Hey there,

I’m getting crash in Unreal Engine because of this 4 lines of code

so can you help me please

1. // Fill out your copyright notice in the Description page of Project Settings.


2. #include "Grabber.h"
3. #include "DrawDebugHelpers.h"
4. #include "Engine/World.h"
5. #include "GameFrameWork/PlayerController.h"

6. // Sets default values for this component's properties
7. UGrabber::UGrabber()
8. {
9. 	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
10. 	// off to improve performance if you don't need them.
11. 	PrimaryComponentTick.bCanEverTick = true;
12. }


13. // Called when the game starts
14. void UGrabber::BeginPlay()
15. {
16. 	Super::BeginPlay();

17. 	FindPhysicsComponent();
18. 	SetupInputComponent();
19. }

20. void UGrabber::FindPhysicsComponent()
21. {
22. 	PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();

23. 	if (PhysicsHandle)
24. 	{

25. 	}
26. 	else
27. 	{
28. 		UE_LOG(LogTemp, Error, TEXT("No Physics Handle Component found on %s"), *GetOwner()->GetName());
29. 	}
30. }

31. void UGrabber::SetupInputComponent()
32. {
33. 	InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();

34. 	if (InputComponent)
35. 	{
36. 		UE_LOG(LogTemp, Error, TEXT("Grab Component Found!"));
37. 		InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabber::Grab);
38. 		InputComponent->BindAction("Grab", IE_Released, this, &UGrabber::Release);
39. 	}
40. }


41. void UGrabber::Grab()
42. {
43. 	UE_LOG(LogTemp, Warning, TEXT("Pressed"));

44. 	FVector PlayerViewPointLocation;
45. 	FRotator PlayerViewPointRotation;

46. 	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerViewPointLocation, PlayerViewPointRotation);

47. 	FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
48. 	
49. 	FHitResult HitResult = GetFirstPhysicsBodyInReach();

50. 	UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();

51. 	if (HitResult.GetActor())
52. 		PhysicsHandle->GrabComponentAtLocation(
53. 			ComponentToGrab,
54. 			NAME_None,
55. 			LineTraceEnd
56. 		);

57. }

58. void UGrabber::Release()
59. {
60. 	UE_LOG(LogTemp, Warning, TEXT("Released"));
61. }


62. // Called every frame
63. void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
64. {
65. 	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

66. 	FVector PlayerViewPointLocation;
67. 	FRotator PlayerViewPointRotation;

68. 	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerViewPointLocation, PlayerViewPointRotation);

69. 	FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;

70. 	if (PhysicsHandle->GrabbedComponent)
71. 	{
72. 		PhysicsHandle->SetTargetLocation(LineTraceEnd);
73. 	}
74. 	else
75. 	{
76. 		UE_LOG(LogTemp, Warning, TEXT("LOOOOOOOOL"));
77. 	}

78. }




79. FHitResult UGrabber::GetFirstPhysicsBodyInReach() const
80. {


81. 	FVector PlayerViewPointLocation;
82. 	FRotator PlayerViewPointRotation;

83. 	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerViewPointLocation, PlayerViewPointRotation);

84. 	FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;

85. 	FHitResult Hit;

86. 	FCollisionQueryParams TraceParams(FName(TEXT("")), false, GetOwner());

87. 	GetWorld()->LineTraceSingleByObjectType(
88. 		OUT Hit,
89. 		PlayerViewPointLocation,
90. 		LineTraceEnd,
91. 		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
92. 		TraceParams
93. 	);

94. 	if (Hit.GetActor())
95. 	{
96. 		UE_LOG(LogTemp, Error, TEXT("%s"), *Hit.GetActor()->GetName());
97. 	}

98. 	return Hit;
99. }

And this is the error

LoginId:025ae4024e9d11c86ea01586534be107

EpicAccountId:aeba41ac213949ba8da89e8ee0d04b75

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000000c0

UE4Editor_Bulding_Escape_1706!UGrabber::TickComponent() [D:\Unreal Engine Projects\Bulding_Escape\Source\Bulding_Escape\Grabber.cpp:96]

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_Core

UE4Editor_Core

UE4Editor_Core

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_Engine

UE4Editor_UnrealEd

UE4Editor_UnrealEd

UE4Editor

UE4Editor

UE4Editor

UE4Editor

UE4Editor

UE4Editor

kernel32

ntdll

I believe I’m talking to you on Udemy about this?

Privacy & Terms