Access Violation After Pressing Play

VS triggers a break point as soon a I press play. Here’s the notification it gives me:

Unhandled exception at 0x00007FFCD4CE3793 (UE4Editor-testFlyingProject-Win64-DebugGame.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x00000000000003E8.

I believe I’ve narrowed it down to this line of code in my Pawn class:

Mesh->AddAngularImpulse(FVector(1, 0, 0));

where Mesh is a UStaticMeshComponent. There are four functions that use Mesh->AddAngularImpulse() but only three of them cause this access violation. The three that cause the violation are called by input axis from my Playercontroller class, while the fourth function that does not cause the violation is called by an action input from my Playercontroller class. If I try to access Mesh within those three functions at all, it causes an access violation. This bug only popped up after I switched from handling input in the pawn, to handling it in the Playercontroller.

Could I be calling the function too early when Mesh is not valid yet? I tried:

if (!Mesh) return;

before I use Mesh->AddAngularImpulse() but it triggered an access violation on that^ line.

Any help would be great!

And here’s the callstack:

UE4Editor-testFlyingProject-Win64-DebugGame.dll!AIFO::Pitch(float pitch) Line 96 C++
UE4Editor-testFlyingProject-Win64-DebugGame.dll!AIFOController::Pitch(float pitch) Line 38 C++
UE4Editor-testFlyingProject-Win64-DebugGame.dll!TBaseUObjectMethodDelegateInstance<0,AIFOController,TTypeWrapper cdecl(float)>::Execute(float <Params_0>) Line 682 C++
UE4Editor-Engine.dll!UPlayerInput::ProcessInputStack(const TArray<UInputComponent *,FDefaultAllocator> & InputComponentStack, const float DeltaTime, const bool bGamePaused) Line 1076 C++
UE4Editor-Engine.dll!APlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused) Line 2367 C++
UE4Editor-Engine.dll!APlayerController::TickPlayerInput(const float DeltaSeconds, const bool bGamePaused) Line 3728 C++
UE4Editor-Engine.dll!APlayerController::PlayerTick(float DeltaTime) Line 2045 C++
UE4Editor-Engine.dll!APlayerController::TickActor(float DeltaSeconds, ELevelTick TickType, FActorTickFunction & ThisTickFunction) Line 3801 C++
UE4Editor-Engine.dll!FActorTickFunction::ExecuteTick(float DeltaTime, ELevelTick TickType, ENamedThreads::Type CurrentThread, const TRefCountPtr & MyCompletionGraphEvent) Line 119 C++
UE4Editor-Engine.dll!FTickTaskSequencer::FTickFunctionTask::DoTask(ENamedThreads::Type CurrentThread, const TRefCountPtr & MyCompletionGraphEvent) Line 322 C++
UE4Editor-Engine.dll!TGraphTaskFTickTaskSequencer::FTickFunctionTask::ExecuteTask(TArray<FBaseGraphTask *,FDefaultAllocator> & NewTasks, ENamedThreads::Type CurrentThread) Line 671 C++
UE4Editor-Core.dll!FTaskThread::ProcessTasks(int QueueIndex, bool bAllowStall) Line 428 C++
UE4Editor-Core.dll!FTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 271 C++
UE4Editor-Core.dll!FTaskGraphImplementation::WaitUntilTasksComplete(const TArray<TRefCountPtr,TInlineAllocator<4,FDefaultAllocator> > & Tasks, ENamedThreads::Type CurrentThreadIfKnown) Line 984 C++
UE4Editor-Engine.dll!FTaskGraphInterface::WaitUntilTaskCompletes(const TRefCountPtr & Task, ENamedThreads::Type CurrentThreadIfKnown) Line 188 C++
UE4Editor-Engine.dll!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup WorldTickGroup, bool bBlockTillComplete) Line 187 C++
UE4Editor-Engine.dll!FTickTaskManager::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 722 C++
UE4Editor-Engine.dll!UWorld::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 696 C++
UE4Editor-Engine.dll!UWorld::Tick(ELevelTick TickType, float DeltaSeconds) Line 1114 C++
UE4Editor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1329 C++
UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 347 C++
UE4Editor.exe!FEngineLoop::Tick() Line 2257 C++
UE4Editor.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE
* hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 142 C++
UE4Editor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 191 C++

So I figured it out and the problem was that my PlayerController class’s input functions were starting to be called before my Pawn was fully initialized or something. In the PlayerController, all I had to do is do:

if (Pawn)


if (!Pawn) return;


and this fixed the problem. No more access violation! yay!
Hope this helps anyone who has a similar problem.