Behavior tree crash after finishing one task and before starting next task

I have a behavior tree that do patrolling with waypoints i assign to it. When it sees the player it goes to attack mode and start shooting the player. If player stay hidden from AI for more than 10 sec it will go back to patrolling.
I’m having this random crash which is not consistent and it happens after a task is finished and before starting the next task in sequence.

This is the tree and sometimes its crashing after AITask_SetAttackVision and before AITast_GetEnemyLocation.
And sometimes it crash after AITask_FireBullet and before AITask_CheckBulletCount.

The AITask_SetAttackVision blueprint is

and AITask_GetEnemyPosition

In the crash report i see “setAttackVision Finish” but “GetENemy location” is not there. So it crashed after the setAttackVision task is finished and before starting the GetEnemyLocation task.

And the crash doesn’t happen all the time. It happens some times and I tried to isolate the conditions for reproducing the crash but it seems random.

I’m not sure how to debug this or what’s causing this.
Any input is appreciated.
Thanks

EDIT:
The call stack i got from the crash

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

UE4Editor_AIModule!UAIPerceptionComponent::DescribeSelfToGameplayDebugger() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\aimodule\private\perception\aiperceptioncomponent.cpp:704]
UE4Editor_AIModule!FGameplayDebuggerCategory_Perception::CollectData() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\aimodule\private\gameplaydebugger\gameplaydebuggercategory_perception.cpp:33]
UE4Editor_GameplayDebugger!AGameplayDebuggerCategoryReplicator::TickActor() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\gameplaydebugger\private\gameplaydebuggercategoryreplicator.cpp:616]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\actor.cpp:113]
UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:256]
UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:868]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:932]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:679]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1776]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:525]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:1437]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:730]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1340]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1422]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:371]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2859]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launch.cpp:152]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

this is the call stack. If i remember correctly from my days back while writing unit test in visual studio, isn’t c0000005 means trying to access null pointer or something?

I have two functions SetAttackVision and SetPatrollingVision…

ARangedAIController::ARangedAIController() : Super()
{
	PatrollingSightAngle = 60.0f;
	PatrollingSightSenseConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Patrolling Sight Config"));
	AttackingSightSenseConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Attacking Sight Config"));

	if (!PatrollingSightSenseConfig)
	{
		UE_LOG(LogTemp, Warning, TEXT("PatrollingSightSenseConfig is null"));
	}

	if (!AttackingSightSenseConfig)
	{
		UE_LOG(LogTemp, Warning, TEXT("AttackingSightSenseConfig is null"));
	}
}

void ARangedAIController::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	if (PatrollingSightSenseConfig)
	{
		PatrollingSightSenseConfig->SightRadius = 1000.0f;
		PatrollingSightSenseConfig->LoseSightRadius = 1500.0f;
		PatrollingSightSenseConfig->PeripheralVisionAngleDegrees = PatrollingSightAngle;
		PatrollingSightSenseConfig->DetectionByAffiliation.bDetectEnemies = true;
		PatrollingSightSenseConfig->DetectionByAffiliation.bDetectFriendlies = true;
		PatrollingSightSenseConfig->DetectionByAffiliation.bDetectNeutrals = true;
	}

	if (AttackingSightSenseConfig)
	{
		AttackingSightSenseConfig->SightRadius = 1500.0f;
		AttackingSightSenseConfig->LoseSightRadius = 1500.0f;
		AttackingSightSenseConfig->PeripheralVisionAngleDegrees = 180.0f;
		AttackingSightSenseConfig->DetectionByAffiliation.bDetectEnemies = true;
		AttackingSightSenseConfig->DetectionByAffiliation.bDetectFriendlies = true;
		AttackingSightSenseConfig->DetectionByAffiliation.bDetectNeutrals = true;
	}
}

void ARangedAIController::SetAttackingVision()
{
	GetAIPerceptionComponent()->ConfigureSense(*AttackingSightSenseConfig);
}

void ARangedAIController::SetPatrollingVision()
{
	GetAIPerceptionComponent()->ConfigureSense(*PatrollingSightSenseConfig);
}

As shown in code i created the both configs in constructor and initialized their values in BeginPlay(). I swap between two configs.

If you get a callstack you gotta paste it in. What makes you sure it’s BT related?

Cheers,

–mieszko

if i remove the AI character from scene I can play around the level for indefinite amount of time without the crash. It crashes only when AI character is there on scene. So I made a guess. I didnt know that i can get call stack from UE4 until now. I will post the call stack as soon as possible.

i updated the question with call stack.

@MieszkoZ hey thanks for telling me about the being able to print stack trace. I followed the bread crumbs and fixed it.
Basically i’m using ConfigureSense function in wrong way.

I found out the right way to change the configuration of senses in this post.

I learned new thing today. I cannot mark the reply as answer sorry for that. Thanks again for the help.