When I press play in the unreal engine it crashes the unreal engine.
After some changes in the code, it crashes again.
Then I run with the debugger after I press play in the unreal engine vs studio shows me Unhandled exception.
Here is the screenshot of the code.
Here is the full code
// Fill out your copyright notice in the Description page of Project Settings.
#include "Grabber.h"
#include"DrawDebugHelpers.h"
#include"GameFramework/PlayerController.h"
#include"GameFramework/Actor.h"
#include"Engine/World.h"
#define OUT
// Sets default values for this component's properties
UGrabber::UGrabber()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UGrabber::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("Grabber Report Reporting to duty:"));
}
// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
//getplayer point in this tick
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation,OUT PlayerViewPointRotation);
///Draw a ray traced in the world to visualize
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
DrawDebugLine(
GetWorld(),
PlayerViewPointLocation,
LineTraceEnd,
FColor(244,0,0),
false,
0.0f,
0.0f,
10.0f
);
///Setup query parameters
FCollisionQueryParams TraceParameters(FName(""), false, GetWorld());
///Raycast(AKA-Raycast)out to reach distance
FHitResult Hit;
GetWorld()->LineTraceSingleByObjectType(
OUT Hit,
PlayerViewPointLocation,
LineTraceEnd,
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParameters
);
///See what we hit
if (Hit.GetActor()) {
UE_LOG(LogTemp, Warning, TEXT("THe actor it hitted is: %s"), *Hit.GetActor()->GetName());
}
}