Detour Crowd does crash after adding a new bot in editor

Hi there.

I have a problem with the detour crowd system. Some time ago i had the problem that on simulate/play the game in editor, the editor crashes randomly while playing when using detour crowd. The error message was missing interface implementation or something. i could fix this by registering the crowd agents in the constructor of the my base character class (bots and player-characters are children of that class) and it works just fine until i upgrade from ue4.21.2 to 4.25.3.

Now, when i am adding a new bot (drag and drop new blueprint from my bot class) to a level and start game/simulate in editor it crashes instandly with a new error message, se below:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000008

UE4Editor_AIModule!UCrowdManager::UpdateSelectedDebug() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\AIModule\Private\Navigation\CrowdManager.cpp:872]
UE4Editor_AIModule!UCrowdManager::DebugTick() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\AIModule\Private\Navigation\CrowdManager.cpp:1118]
UE4Editor_Engine!FTickableGameObject::TickObjects() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\Engine\Private\Tickable.cpp:151]
UE4Editor_UnrealEd!UEditorEngine::Tick() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1725]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:414]
UE4Editor!FEngineLoop::Tick() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:4850]
UE4Editor!GuardedMain() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:169]
UE4Editor!GuardedMainWrapper() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
UE4Editor!WinMain() [D:\Build\++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:268]
UE4Editor!__scrt_common_main_seh() [d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

When i am adding a bot, save and restart the editor it works as expected without a crash. It still looks like that something is not working correctly with agent registration but i can’t find out why.

Like in the description of the detour crowd system by epic i addet the crowd interface to the character class, implement the interface functions like GetCrowdAgentLocation(), GetCrowdAgentVelocity()… in the character class, registering those actors with

UCrowdManager* CrowdManager = UCrowdManager::GetCurrent(this);
	if (CrowdManager)
	{
		ICrowdAgentInterface* MyAgent = Cast<ICrowdAgentInterface>(this);
		CrowdManager->RegisterAgent(MyAgent);
	}

in the constructor of the character class and change the constructor of my ai controller to

AUE4_AIController::AUE4_AIController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))

Do i miss something else?

Some more informations:
I testet this on multiple levels, all with the same result.
Unregistering bots/agents by deleting a bot in editor or killing the bot ingame does work without any problems.
I have also tested this with different meshes, humanoids including the original epic mannequin mesh, other humanoid characters and also no humanoid to check if there may be a problem with the mesh/collision/rig itself, but allways the same result.

maybe somebody else has an idea whats going on. thank you very much!

Oh by the way. Now i addet a bot, klicked on save level and the editor crashed instantly on the saving process with this message.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION 0x00000000

UE4Editor_AIModule!UCrowdManager::PrepareAgentStep() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\AIModule\Private\Navigation\CrowdManager.cpp:762]
UE4Editor_AIModule!UCrowdManager::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\AIModule\Private\Navigation\CrowdManager.cpp:237]
UE4Editor_NavigationSystem!UNavigationSystemV1::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\NavigationSystem\Private\NavigationSystem.cpp:998]
UE4Editor_Engine!UWorld::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1492]
UE4Editor_UnrealEd!UEditorEngine::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1515]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:414]
UE4Editor!FEngineLoop::Tick() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:4850]
UE4Editor!GuardedMain() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:169]
UE4Editor!GuardedMainWrapper() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:137]
UE4Editor!WinMain() [D:\Build++UE4+Licensee\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:268]
UE4Editor!__scrt_common_main_seh() [d:\agent_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

Should i register the agent in the begin play function of my character class instead of the constructor?
Seems like that something is messed up.

Sorry for necroposting. However, I’ve just encountered this very behavior after implementing my save-load system and have a solution. The solution is in fact very simple.

As a background. I have a component declared like this:

class PROJECTEGYPT_API UPlayerCrowdHelper : public UActorComponent, public ICrowdAgentInterface

And then doing a call on begin play:

void UPlayerCrowdHelper::BeginPlay()
{
	Super::BeginPlay();

	if (const auto CrowdManager = UCrowdManager::GetCurrent(this))
		CrowdManager->RegisterAgent(this);
}

The only thing missing was just unregistering the component:

void UPlayerCrowdHelper::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);
	
	if (const auto CrowdManager = UCrowdManager::GetCurrent(this))
		CrowdManager->UnregisterAgent(this);
}

Done that, no more random crashes after destroying and possibly recreating a pawn. Hope the solution helps somebody in the future.