Game Crashes with character begin play

By game crashes when my character runs cone in beginplay() The problem seems to be coming from my game mode but there is no code only a blueprint with the default pawn changed.
here is the crash log

 Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000148
    
    UE4Editor_Engine
    UE4Editor_EnergySuckers_9891!ATP_Character::BeginPlay() [C:\Users\noahd\Documents\Unreal Projects\EnergySuckers\Source\EnergySuckers\TP_Character.cpp:43]
    UE4Editor_Engine
    UE4Editor_Engine
    UE4Editor_Engine
    UE4Editor_Engine
    UE4Editor_Engine
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor_UnrealEd
    UE4Editor
    UE4Editor
    UE4Editor
    UE4Editor
    UE4Editor
    kernel32
    ntdll

The code on character.Cpp line 43 is BeginPlay()

void ATP_Character::BeginPlay()
{
	Super::BeginPlay();

	FActorSpawnParameters SpawnInfo;
	SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	
	Gun = GetWorld()->SpawnActor<AGunBase>(GunClass);
	Gun->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("root"));
	Gun->SetOwner(this);
	
	InventoryWidget = CreateWidget(GetWorld(), InventoryClass);

	if (InventoryWidget != nullptr)
	{
		InventoryWidget->AddToPlayerScreen();
	}
}

I removed all code from the game mode and nothing changed. The game mode is just the generic mode made by Unreal at the creation of the project.

nothing jumps out at me from the things you are posted.

atm I would suspect that begin play is called on a nullptr
which would be super weird and mean you do something strange with character creation.

the reason why that would explain the behavior you are seeing is
calling functions on nullptr objects can create a crash later in the call because they only crash when they try to access member parameter

so I would actually suspect that it crashes in the unreal begin play when it tries to access an unreal member parameter

to test my suspicion try removing the override for begin play and see if it still crashes.

I just tested spawning the character with the gamemode and then it crashed with the same errors so the problem seems to be the game mode I will try to create a new one and see if the problem persists.

The game didn’t crash but now I can’t move the Input still works but nothing happens.

I just solved the problem I had been spawning in the C++ class of the character not the blueprint child. switching it solved the problem.