Hi fellows, I’m making a game using C++ and blueprints, but I’m stuck on an access violation error. It doesn’t happens all the time, it’s something random, but always on the same line of the code. The stack of the error is:
Access violation - code c0000005 (first/second chance not available)
UE4Editor_Engine!APawn::GetController() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\pawn.cpp:433]
UE4Editor_Squad51_663!UEnemySpawner::ExecuteAction() [c:\users\marci_000\projects\squad51\source\squad51\enemies\enemyspawner.cpp:10]
UE4Editor_Squad51_663!USquadMemberSpawner::ExecuteAction() [c:\users\marci_000\projects\squad51\source\squad51\enemies\squadspawner.cpp:9]
UE4Editor_Squad51_663!AEventsTimeLine::ExecuteCurrentAction() [c:\users\marci_000\projects\squad51\source\squad51\eventstimeline.cpp:64]
UE4Editor_Engine!FTimerUnifiedDelegate::Execute() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\public\timermanager.h:38]
UE4Editor_Engine!FTimerManager::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\timermanager.cpp:439]
UE4Editor_Engine!UWorld::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\leveltick.cpp:1212]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\editor\unrealed\private\editorengine.cpp:1347]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\editor\unrealed\private\unrealedengine.cpp:361]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\launchengineloop.cpp:2427]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll
And this is my function, where the error occurs (on Pawn->GetController()):
void UEnemySpawner::ExecuteAction(FTimeLineEvent TimeLineEvent)
{
FActorSpawnParameters Parameters;
FTransform Transform = CalculateTransform();
APawn* Pawn = (APawn*)TimeLineEvent.OwnerTimeLine->GetWorld()->SpawnActor(EnemyClass, &Transform, Parameters);
AEnemyAIController* AIController = (AEnemyAIController*)Pawn->GetController();
if (AIController != nullptr && AIController->IsA<AEnemyAIController>())
{
AIController->MovementSettings = MovementSettings;
AIController->DirectionAngle = CalculateDirectionAngle();
}
AfterSpawn(Pawn);
}
FTimeLineEvent is a struct of my project, AEnemyAIController is a class that extends AAIController (and it is setted by default on the blueprint; like I said before, sometimes it works, so I’m sure the controller is setted).
This function is called inside a callback of a timer, can it be the cause of the issue?
Unfortunately, i’m also not able to use a breakpoint to investigate because it doesn’t work either… but I think it is something for another thread.
- Sorry for my bad english, but for me it’s hard to explain this issue even in my native language
Edit: I changed the title of the question to the real issue. Otherwise, some people with the same issue could not find it.