Unreal Engine 4.22 crashes when play

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());
	}
	



}


Make sure you have all of the headers needed (its one of the downsides to the newer approach) such as for Grabber.cpp:

#include “Grabber.h”
#include “GameFramework/Actor.h”
#include “DrawDebugHelpers.h”
#include “CollisionQueryParams.h”
#include “Engine/World.h”
#include “Components/InputComponent.h”
#include “Components/PrimitiveComponent.h”
#include “GameFramework/PlayerController.h”
#include “GameFramework/Character.h”

If its not that then it should be a code problem but you don’t show everything so.

Suppose you could also try fully cleaning the project.

There might also be something else there in the output log that specifies what’s happening.

1 Like

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());
	}
	



}


Oh I fixed it was in the code very hard to find

Before:

FCollisionQueryParams TraceParameters(FName(""), false, GetWorld());

After:

FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetOwner());

Can anyone explain this line of code.

It’s constructing an object of type FCollisionQueryParams

And using this constructor

FCollisionQueryParams
(
    FName InTraceTag,
    bool bInTraceComplex,
    const AActor * InIgnoreActor
)

The key part being you saying it should ignore the world as opposed to the owner.

Don’t think that would have caused a crash on BeginPlay though. You most likely just needed to rebuild.

1 Like

Yes, that was it :slight_smile: Good job.

FCollisionQueryParams requires an actor to ignore but also an AActor. For whatever reason that’s how they coded it. Someone else would have coded it differently.

Also, not sure why your VS didn’t alert you to GetWorld(). It wouldn’t even let me compile and flagged it as incorrect. VS 2019.

GetWorld returns a UWorld not an AActor as well so borked that would be.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms