I’m currently in a game jam and i’m making a shop.
Whenever the player leaves the shop the game crashes. This is because i’m calling a function on the player to remove the shop when they leave. (I de-refrence the shop). my Guess is that I’m causing an infinate loop by EndOverlap and BeginOverlap constantly fighting each other to add and remove the shop?? Could you guys confirm if that is the case and how would I best fix this?
PS: Shop is an actor component I have both overlap functions called in Blueprints on the Shop Pawn right now.
bIsShopping is a private bool on defiend in Player.h.
(In Shop.ccp)
void UAC_Trader::OnActorOverlap(AHumanChar *OtherActor)
{
if (OtherActor->StaticClass == AHumanChar::StaticClass)
{
auto Player = OtherActor;
//AskToTrade(Player); //Does Below Code now
Player->SetTrader(this); //Sets ShopKeeper Player can talk to, to this function
}
else { UE_LOG(LogTemp, Warning, TEXT("Object entered shop... Wasn't seen as a Player. No Shopping Request was sent."))}
}
void UAC_Trader::OnActorEndOverlap(AHumanChar * OtherActor)
{
if (OtherActor->StaticClass == AHumanChar::StaticClass)
{
auto Player = OtherActor;
Player->RemoveTrader();
}
else { UE_LOG(LogTemp, Warning, TEXT("Object Left shop... Wasn't seen as a Player. No Leave Message was sent.")) }
}
(In Player.ccp)
//Set Trade is called when player enters a shop and the shop wants to trade
UAC_Trader* AHumanChar::SetTrader(UAC_Trader * Shop)
{
//Create a Widget called ShopText Telling Player to "Press Interact Button" to shop//OR add it to viewport
//Set player in the shop
bIsShopping = true;
MyShop = Shop;
return MyShop;
}
void AHumanChar::RemoveTrader()
{
MyShop = nullptr; //Clear Shop refrence
bIsShopping = false; // No Longer Shopping
//TODO close widgets
}
A few things to note. I tested Remove Trader() to see if it was a nullpointer error from the MyShop… Its not. Unless i’m also getting a nullpoint error from a bool.
ERROR MESSAGE:
Access violation - code c0000005 (first/second chance not available)
UE4Editor_SaveTheEnvironment_1313!AHumanChar::RemoveTrader() [c:\video game making\projects\gamejam\savetheenvironment\save-the-environment-jam\source\savetheenvironment\humanchar.cpp:119]
UE4Editor_SaveTheEnvironment_1313!UAC_Trader::execOnActorEndOverlap() [c:\video game making\projects\gamejam\savetheenvironment\save-the-environment-jam\source\savetheenvironment\ac_trader.h:24]
UE4Editor_CoreUObject!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4861]
UE4Editor_CoreUObject!UObject::CallFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:816]
UE4Editor_CoreUObject!UObject::ProcessContextOpcode() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:2330]
UE4Editor_CoreUObject!UObject::ProcessInternal() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1031]
UE4Editor_CoreUObject!UObject::CallFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:940]
UE4Editor_CoreUObject!UObject::ProcessInternal() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1031]
UE4Editor_CoreUObject!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4861]
UE4Editor_CoreUObject!UObject::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1480]
UE4Editor_Engine!AActor::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\engine\private\actor.cpp:713]
UE4Editor_Engine!AActor::ReceiveActorEndOverlap() [d:\build\++ue4\sync\engine\intermediate\build\win64\ue4editor\inc\engine\actor.gen.cpp:922]
UE4Editor_Engine!UPrimitiveComponent::EndComponentOverlap() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:2573]
UE4Editor_Engine!UPrimitiveComponent::UpdateOverlapsImpl() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:3009]
UE4Editor_Engine!USceneComponent::EndScopedMovementUpdate() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:827]
UE4Editor_Engine!FScopedMovementUpdate::~FScopedMovementUpdate() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:3378]
UE4Editor_Engine!UCharacterMovementComponent::PerformMovement() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\charactermovementcomponent.cpp:2349]
UE4Editor_Engine!UCharacterMovementComponent::TickComponent() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\charactermovementcomponent.cpp:1241]
UE4Editor_Engine!FActorComponentTickFunction::ExecuteTickHelper<<lambda_3709318d6805ded621dc256d05754a1f> >() [d:\build\++ue4\sync\engine\source\runtime\engine\classes\gameframework\actor.h:3143]
UE4Editor_Engine!FActorComponentTickFunction::ExecuteTick() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\actorcomponent.cpp:800]
UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4\sync\engine\source\runtime\core\public\async askgraphinterfaces.h:829]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4\sync\engine\source\runtime\core\private\async askgraph.cpp:679]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4\sync\engine\source\runtime\core\private\async askgraph.cpp:575]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4\sync\engine\source\runtime\core\private\async askgraph.cpp:1444]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private icktaskmanager.cpp:556]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private icktaskmanager.cpp:1474]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private\leveltick.cpp:783]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4\sync\engine\source\runtime\engine\private\leveltick.cpp:1460]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4\sync\engine\source\editor\unrealed\private\editorengine.cpp:1726]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:403]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3699]
UE4Editor!GuardedMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launch.cpp:174]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:145]
UE4Editor!WinMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:276]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283]
kernel32
ntdll