Unreal Engine crashing when approaching towers

Every time i enter the tower’s range, the engine crashes and points me to the rotate turret call in Tower.cpp and the original function in BasePawn.cpp. My code is identical to the lessons.

Just guessing here but did you check if TurretMesh was set anywhere? If it’s nullptr when RotateTurret is called the game will crash because you are trying to dereference it without checking that it actually points to a live object first.

What does the crash report say?

LoginId:ab55bd734aac87c781d663a655d91f2d
EpicAccountId:eb7373cde98440fc87c2ea064afb057b

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000002a0

UnrealEditor_ToonTanks_patch_0!ABasePawn::RotateTurret() [C:\Users\zdowd\UnrealGames\ToonTanksProjectSetup_4.25\ToonTanks\Source\ToonTanks\BasePawn.cpp:26]
UnrealEditor_ToonTanks!ATower::Tick() [C:\Users\zdowd\UnrealGames\ToonTanksProjectSetup_4.25\ToonTanks\Source\ToonTanks\Tower.cpp:16]
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll

It’s referring to the rotate turret function in basepawn.cpp and the rotate turret call in Tower.cpp

tried a null check on rotate turret and it fixed the crash but the turrets still don’t rotate

What’s line 26?

The third image. The RotateTurret function. It functions perfectly with rotating the tank but not the turret.

I’m aware of that but what is the specific line of code?

FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();

And how did you add the null check?

if (TurretMesh)

{

    FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();

    FRotator LookAtRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f);

    TurretMesh->SetWorldRotation(LookAtRotation);

}

This prevents the crash, but still doesn’t rotate the turrets

Sorry I completely missed the fact that you said that it fixed the crash.

Where have you assigned TurretMesh?

This is basepawn.cpp

Odd, I’d suggest you try deleting the Binaries and intermediate folders and rebuilding. If that doesn’t work try remaking the blueprint (don’t duplicate).

Rebuilding the BP worked. Idk how but it did

1 Like

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

Privacy & Terms