Crash when using Possess and UnPossess

So, I made a character , a car and what I want to do is : if the player is near the car and if the player presses f, then the character gets unpossessed and the car possessed. I havent created the animations yet. But for some reason , the editor crashes when I press f (and I am near the car)and I dont know why . Here is the “EnterVehicle” method .

void AMyCharacter::EnterVehicle() {

if (CheckIfNearCar()) {

	APlayerController* controller = UGameplayStatics::GetPlayerController(GetWorld(), 0); 

	UE_LOG(LogTemp, Warning, TEXT("It doesnt work"));

	controller->UnPossess();

	controller->Possess(ab); //ab is the instance of the vehicle class
	
	UE_LOG(LogTemp, Warning, TEXT("IT WORKS"));

	

}

}

I have checked the logs out . There isnt something that indicates the source of the problem and both “It doesnt work” and “IT WORKS” are printed. If you know whats going on , please help me.

Try removing the call to unpossess, when you tell your controller to possess another pawn, the engine will handle the unpossess call already if I remember correctly. You also might want to wrap the call in a check to see if the controller pointer is valid before using it.

If this doesn’t work can you post the output when the crash occurs and the call stack?

Edit : Adding some source code.

 if (CheckIfNearCar()) {
 
    APlayerController* controller = UGameplayStatics::GetPlayerController(GetWorld(), 0); 
    
    if(controller != nullptr && ab != nullptr)
    {
        controller->Possess(ab); //ab is the instance of the vehicle class
    }
 }

link text

As far as call stack is concerned , I dont have the debugging symbols required to display call stack.It still crashes . I have checked the validity of the “ab” reference and it seems to be ok. Should I install debugging symbols? And thanks for the quick reply!

As far as “ab” is concerned , this is how I assign the vehicle to it:

		ab = dynamic_cast<AMyProject6Pawn*>(HitData.GetActor());

where HitData is an object of FHitResult class

I downloaded the debugging symbols , here is the summary info

LoginId:8684ca454ac1c91df9ffd2b56a98359f
EpicAccountId:81ce067c34154713ad9f8daa8adafb5c

Access violation - code c0000005 (first/second chance not available)

UE4Editor_AtLeastITry_4936!AMyCharacter::MoveForward() [c:\users\dimos\documents\unreal projects\atleastitry\source\atleastitry\mycharacter.cpp:87]
UE4Editor_Engine!UPlayerInput::ProcessInputStack() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\userinterface\playerinput.cpp:1238]
UE4Editor_Engine!APlayerController::ProcessPlayerInput() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:2471]
UE4Editor_Engine!APlayerController::TickPlayerInput() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:4232]
UE4Editor_Engine!APlayerController::PlayerTick() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:2135]
UE4Editor_Engine!APlayerController::TickActor() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\playercontroller.cpp:4327]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\actor.cpp:134]
UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:273]
UE4Editor_Engine!TGraphTask::ExecuteTask() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:829]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:665]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:574]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1355]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:542]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:1449]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:770]
UE4Editor_Engine!UWorld::Tick() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1429]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build++ue4+release-4.19+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1693]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build++ue4+release-4.19+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:401]
UE4Editor!FEngineLoop::Tick() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3339]
UE4Editor!GuardedMain() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:144]
UE4Editor!WinMain() [d:\build++ue4+release-4.19+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:223]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

I solved my problem . The solution is checking if ALL the pointers I used (even if they have nothing to do with the possess and unpossess methods) are null or not.