SimpleShooter UE5 Crashing on when pressing play after compiling

Hey all, coming back to this tutorial after a break, I left off with lecture 20 where I was spawning debug points but they were hitting my character instead of the wall. On my return, I noticed that when playing I no longer see a muzzle flash on my character’s gun, nor does it spawn any debug points. I decided to compile and play, but my Ue5 crashes after this giving my this error:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000001d0
UnrealEditor_ShooterSimple_patch_0!AShooterCharacter::BeginPlay() [D:\SimpleShooter\ShooterSimple\Source\ShooterSimple\ShooterCharacter.cpp:23

It seems that its a pointer error of some sort, or its trying to find something that isnt there, but Im not exactly sure on what it is, I know my Gun is attached to my character via, the skeletal mesh. it seems it has a probelm with me using the “this” key word?
Here is my code for my ShooterCharacter.cpp

#include "ShooterCharacter.h"
#include "Gun.h"

// Sets default values
AShooterCharacter::AShooterCharacter()
{
 	// Set this character 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 AShooterCharacter::BeginPlay()
{
	Super::BeginPlay();
	
	Gun = GetWorld()->SpawnActor<AGun>(GunClass);
	GetMesh()->HideBoneByName(TEXT("weapon_r"), EPhysBodyOp::PBO_None);
	Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));
	Gun->SetOwner(this);

	
}

// Called every frame
void AShooterCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AShooterCharacter::MoveForward(float AxisValue)
{
	AddMovementInput(GetActorForwardVector() * AxisValue);
}

void AShooterCharacter::MoveRight(float AxisValue)
{
		AddMovementInput(GetActorRightVector() * AxisValue);

}

void AShooterCharacter::LookUp(float AxisValue)
{
	AddControllerPitchInput(AxisValue);
}

void AShooterCharacter::LookRight(float AxisValue)
{
		AddControllerYawInput(AxisValue);

}

void AShooterCharacter::Shoot()
{
	Gun->PullTrigger();
}



// Called to bind functionality to input
void AShooterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	PlayerInputComponent->BindAxis(TEXT("MoveForward"),this,&AShooterCharacter::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("MoveRight"),this,&AShooterCharacter::MoveRight);

	PlayerInputComponent->BindAxis(TEXT("LookUp"),this,&AShooterCharacter::LookUp);
	PlayerInputComponent->BindAxis(TEXT("LookRight"),this,&AShooterCharacter::LookRight);
	PlayerInputComponent->BindAction(TEXT("Jump"),EInputEvent::IE_Pressed,this,&ACharacter::Jump);
	PlayerInputComponent->BindAction(TEXT("Fire"),EInputEvent::IE_Pressed,this,&AShooterCharacter::Shoot);



}

I would suspect the Gun isn’t spawning for whatever reason and then this line would dereference a null pointer

Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeaponSocket"));

Are you sure you set the GunClass in the blueprint?

So sorry for the super late reply, but It does appear to be attached to my skeleton mesh in my shooter character blueprint.

this is what the skeleton looks like as well, It the character and gun seem to look different though, but im not sure if thats the cause of it.

Also I note that the Anim Class is named ABP_Shooter_C, but the asset the magnifying glass points to is called ABP_Shooter. Not sure if thats an issue either.

That’s not the gun that is being spawned. That is the gun on the mesh that is being hidden with this line of code

Source/SimpleShooter/ShooterCharacter.cpp · master · GameDev.tv / Unreal 5 CPP / Simple Shooter UE4 · GitLab

The gun class is this
image
which is due to this code
Source/SimpleShooter/ShooterCharacter.h · master · GameDev.tv / Unreal 5 CPP / Simple Shooter UE4 · GitLab
and what we use that blueprint to spawn it here
Source/SimpleShooter/ShooterCharacter.cpp · master · GameDev.tv / Unreal 5 CPP / Simple Shooter UE4 · GitLab

Privacy & Terms