Exception_access_violation

This code was working and broke dunno why.

Fire Function


void ABasePawn::Fire()
{
if (CanShoot = true)
{
switch (FireModeNumber)
{
case 1:

PullTrigger();

break;
case 2:

BurstFire();

break;
case 3:

PullTrigger();
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &ABasePawn::PullTrigger, ShootDelay, true);

break;
}
}

}

Please help.

Well, first off



if (CanShoot = true)


Is always going to be true because you are ASSIGNING true rather than testing which would be:



if (CanShoot == true)


Other than that, the world may be invalid somehow. You can test for that in your if statement:



if (CanShoot && GetWorld() != nullptr)
{
   // ...
}


Thanks for help.
I was aware of first problem and I’ve fixed it.

Sadly second advice you gave me did nothing

I’ve got this error.

bool CanShoot is declared in header file in private section.

Could be the object itself is invalid. Hard to say. Make sure you go into the Epic Launcher -> Select your UE4 Engine Install -> And add the option for “Editor Debug Symbols”

What does it change?
Also ,I think this function broke after i created player controller.

I did it, what next?

I deleted Binaries and Intermediate and crash massage changed.

No idea, it looks like you have something going on when you use your input. Whatever the problem is, it’s at line 67 of your BasePawn.cpp, so you likely have some invalid object on that line.

You can’t really debug code like this. Run the editor through Visual Studio, and see what causes the crash. Just press F5 in visual studio. Once the crash occurs, Visual Studio will pause the program execution, and show you whats going on.

Gives me this massage
unable.jpg
Unused is indeed empty.
I think visual studio don’t know real UE4’s directory.

I found bug. It is too dumb to tell here.

1 Like