Download

UE4 crashes while spawing custom pawn class. ( EXCEPTION_ACCESS_VIOLATION)

Hi all,
I have created a custom pawn c++ class and assigned to default pawn in GameMode details tab. Used PlayerStart component to spawn. The game worked well.
But now , I removed the PlayerStart component and directly using the Pawn in scene. This time , the engine crashes throwing the following error.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000420

UE4Editor_Engine!APlayerController::GetInputTouchState() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\PlayerController.cpp:5142]
UE4Editor_ue_spaceshooter_4477!AMyDefaultCPPPawn::Tick() [H:\Unreal Engine projects\ue_cpp_spaceshooter\Source\ue_spaceshooter\MyDefaultCPPPawn.cpp:35]
UE4Editor_Engine!AActor::TickActor() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:1093]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:173]
UE4Editor_Engine!FTickFunctionTask::DoTask() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:284]
UE4Editor_Engine!TGraphTask::ExecuteTask() [D:\Build++UE4\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:886]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\Build++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:709]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\Build++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:601]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [D:\Build++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1525]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:564]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1578]
UE4Editor_Engine!UWorld::RunTickGroup() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:782]
UE4Editor_Engine!UWorld::Tick() [D:\Build++UE4\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1457]
UE4Editor_UnrealEd!UEditorEngine::Tick() [D:\Build++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1720]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [D:\Build++UE4\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:426]
UE4Editor!FEngineLoop::Tick() [D:\Build++UE4\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:4836]
UE4Editor!GuardedMain() [D:\Build++UE4\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:169]
UE4Editor!GuardedMainWrapper() [D:\Build++UE4\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
UE4Editor!WinMain() [D:\Build++UE4\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:268]
UE4Editor!__scrt_common_main_seh() [d:\agent_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

This is the code,

AMyDefaultCPPPawn::AMyDefaultCPPPawn()
{
	PrimaryActorTick.bCanEverTick = true;

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));

	Actor_Ship = CreateDefaultSubobject<UChildActorComponent>(TEXT("Actor_Ship"));

	Actor_Ship->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);

}

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

	playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);

	GetMovementComponent()->SetUpdatedComponent(RootComponent);
}

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

	bool bIsCurrentlyPressed;

	if (playerController)
	{
		playerController->GetInputTouchState(ETouchIndex::Touch1, currentTouchPoint.X, currentTouchPoint.Y, bIsCurrentlyPressed);
		playerController->DeprojectMousePositionToWorld(currentTouchPoint, mouseDirection);

		if (bIsCurrentlyPressed)
		{

			FVector deltaTouchPoint = currentTouchPoint - prevTouchPoint;
			FVector deltaOffset = FVector(deltaTouchPoint.X, deltaTouchPoint.Y, 0);

			//this->AddActorWorldOffset(deltaOffset);
			currentActorLocation = this->GetActorLocation();
			currentActorLocation.X += MovementSpeed * deltaOffset.X * DeltaTime;
			currentActorLocation.Y += MovementSpeed * deltaOffset.Y * DeltaTime;

			if (!prevTouchPoint.IsZero())
				SetActorLocation(currentActorLocation);

			prevTouchPoint = currentTouchPoint;

			//UE_LOG(LogTemp, Warning, TEXT("Actor Position : %f, %f"), currentActorLocation.X, currentActorLocation.Y);
		}
	}
}

Kindly let me know what is the cause of this crashing issue.

Thanks

If you removed the PlayerStart one possibility is you are spawning the player inside geometry. AFAIK that will crash things.

@Shmoopy1701 is right I think. You can easily check if it’s a spawning issue by going into the Play settings and setting the spawn to “Current Camera Location”.

Thanks for reply. Actually the issue was due to null pointer in Touch input. The game check touch input even before it gets initialized. Wrote code to null check and it works now.