Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
LostEnemyFix
Fixes EnemyAI's that fail to locate NavMesh by killing them.
| Date uploaded | a day ago |
| Version | 1.1.1 |
| Download link | JacobG5-LostEnemyFix-1.1.1.zip |
| Downloads | 1758 |
| Dependency string | JacobG5-LostEnemyFix-1.1.1 |
This mod requires the following mods to function
BepInEx-BepInExPack
BepInEx pack for Mono Unity games. Preconfigured and ready to use.
Preferred version: 5.4.2100README

v80 Update
Zeekerss implemented the following code implementing part of this mod to the base game:
if (agent.isOnNavMesh)
{
if (destination != prevDestination && agent.SetDestination(destination))
{
prevDestination = destination;
}
}
else
{
Debug.LogError($"Agent '{enemyType.enemyName}' #{thisEnemyIndex}: Agent not on nav mesh when trying to set destination", base.gameObject);
}
The issue is this implementation just spams a brand new error every frame and does not do anything to fix the problem, yet broke my prior implementation by checking for the same issue before calling SetDestination.
Lost Enemy Fix
This mod throws more meaningful errors when an EnemyAi fails to path on Navmesh and kills enemies that throw too many of these errors.
If you play with modded moons, enemies, or interiors. You may have at some point experienced:
[Error : Unity Log] "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
This error can be thrown for several reasons, making it sometimes hard to track the exact source. This could be from a modded enemy being set up wrong, incorrectly placed AI nodes, or blocked navmesh in any modded interior or moon. When this error is thrown this mod will additionally log the EnemyType, position, target destination, enemy behavior state, and if it is outside or inside the facility.

The Fix
In order to fix this lag and console spawn this mod will kill enemies that throw this particular error.
This is configurable:
Aggressive Kills an enemy after it has thrown ONE SetDestination Error.
Reasonable (Default) Kills an enemy after it has thrown several SetDestination Errors.
Off Leaves Vanilla behavior. (Console will be spammed)
With This Mod: (Aggressive Setting)

Without This Mod:

and it keeps going...
Note:
This mod replaces the call to an EnemyAI's Agent with a custom method. If the vanilla error persists creating lag, the culprit is likely a modded enemy that overrides or completely replaces the navigation method of the vanilla EnemyAI. This mod will fix all vanilla enemies and modded enemies that inherit from the vanilla EnemyAI.
Credits
Programming by JacobG5 (Me)
Nikki - Paid me to make this. & made icons.
CHANGELOG
v1.1.1
- Removes Zeekerss v80 check for agent on navemesh which throws and error every frame allowing the code to continue to my patch that prevents errors and handles enemy reloacation and removal.
v1.1.0
- Now checks if agent is on navmesh and only counts errors when not on nav mesh or links.
- Reasonable has been reduced down to 8 from 16 erros before triggering the kill code.
- Added new option to attempt relocation instead of killing when an enemy errors. This option will search 50 units for a navmesh and will kill if it cannot be found in that range. This is now the default.
v1.0.0 Release
- Initial Release