Game crashing


when i press play my project crash, i have been using some code from the course to do another videogame but i dont really know how to fix this crash
here is the code where the crash report the errors

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

#include “Sword.h”

#include “Components/SkeletalMeshComponent.h”

#include “Kismet/GameplayStatics.h”

#include “DrawDebugHelpers.h”

#include “TheLegend.h”

// Sets default values

ASword::ASword()

{

// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned

void ASword::BeginPlay()

{

Super::BeginPlay();

}

// Called every frame

void ASword::Tick(float DeltaTime)

{

Super::Tick(DeltaTime);

}

void ASword::Hitting()

{

FHitResult Hit;

FVector SwordDirection;

bool bSuccess = SwordTraceLine(Hit, SwordDirection);

if(bSuccess)

{

DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Red, true);

AActor* HitActor = Hit.GetActor();

if(HitActor != nullptr)

{

    FPointDamageEvent DamageEvent( Damage, Hit, SwordDirection, nullptr);

    AController* OwnerController = GetOwnerController();

    HitActor-> TakeDamage( Damage,DamageEvent, OwnerController,  this);

}

//if(Sword -> IsOverlappingActor(Enemy))

//{

       //TakeDamage();

//}

}

}

bool ASword::SwordTraceLine(FHitResult &Hit, FVector &SwordDirection)

{

AController* OwnerController = GetOwnerController();

if(OwnerController == nullptr)return(false);

FVector Location;

FRotator Rotation;

OwnerController-> GetPlayerViewPoint(Location,  Rotation);



 SwordDirection = -Rotation.Vector();



FVector End = Location + Rotation.Vector() * MaxRange;




FCollisionQueryParams Params;

Params.AddIgnoredActor(this);

Params.AddIgnoredActor(GetOwner());

return GetWorld() -> LineTraceSingleByChannel(Hit,Location, End, ECollisionChannel::ECC_GameTraceChannel1, Params);

}

AController* ASword::GetOwnerController() const

{

APawn* OwnerPawn = Cast<APawn>(GetOwner());

if(OwnerPawn == nullptr) return nullptr;

return OwnerPawn -> GetController();

}

Hi Bauti_peral,

Thanks for posting your question.
I cant see anything obvious in the code that would cause the crash and admittedly i am very rusty in unreal.
From what i remember however if the code compiles correctly and it crashes on play without an obvious error its usually a blueprint issue so i would check those sword assets over to make sure they are correct and maybe remake them to see if that is the issue.

Let us know how you get on and if this is not the issue then we can take a further look at the problem

1 Like

Privacy & Terms