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