You are viewing a potentially older version of this package. View all versions.
Zaggy1024-PathfindingLagFix-2.1.0 icon

PathfindingLagFix

Improves overall performance by threading vanilla AI pathfinding and patching slow methods.

Date uploaded 6 hours ago
Version 2.1.0
Download link Zaggy1024-PathfindingLagFix-2.1.0.zip
Downloads 3698
Dependency string Zaggy1024-PathfindingLagFix-2.1.0

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100
Zaggy1024-PathfindingLib-0.0.14 icon
Zaggy1024-PathfindingLib

Provides functionality for mod authors to run pathfinding off of the main thread.

Preferred version: 0.0.14

README

PathfindingLagFix

Moves many AI pathfinding tasks off the main thread to improve frame rates significantly, especially for hosts.

Most patches must be tailored to each AI, so this will not affect modded enemies in most cases.

The asynchronous pathfinding jobs are rendered safe from crashing through PathfindingLib.

Frametime graph comparisons:

Before/after on March with late night spawns:

Before After

Support my work:

If you wish to support my continued work, feel free to donate to me at my ko-fi: https://ko-fi.com/zaggy1024

Thanks!

Patches

The enemy behaviors currently patched to run their pathfinding off the main thread include:

  • General enemies:
    • The roaming search patterns used by many enemies (thumpers, hoarding bugs, jesters, etc), including any modded enemies that use this vanilla functionality
    • The checks for valid paths to players to be targeted
  • Bracken:
    • The search for a hiding spot away from the main entrance when no players are targetable
    • The search for a hiding spot away from a player when it is spotted
    • The pathing towards the player out of line of sight when it is hunting
  • Snare flea:
    • The search for a hiding spot at a certain number of paths away from main when no players are present
    • The search for a hiding spot near a player when they are targetable
  • Spore lizard:
    • The search for a hiding spot away from a player when it is spotted
  • Tulip snake:
    • Selection of a node to run away to after dismounting the player
  • Manticoil:
    • The search for a node to fly to when it is disturbed by a player at close range

Other changes include:

  • Bracken:
    • A vanilla bug that causes the bracken to stand in place if spotted within 5 units will no longer occur with the async pathfinding solution.
  • Tulip snake:
    • A patch to prevent small stutters due to calls to Object.FindObjectsByType<FlowerSnakeEnemy>().

Options

The mod is designed to change the behavior of enemies as minimally as possible, but there are some bugs that are incidental to the included patches and cannot be fixed by another mod unless it maintains two different versions of the patch. Therefore, the fixes are included in PathfindingLagFix.

In order to allow easy configuration of these fixes, two presets are included to define the general effect of options that can change behavior:

  • OnlyFixes: The default, this will select only options that make what are deemed to be fixes to bugs in the vanilla behavior of enemies.
  • Vanilla: This will attempt to retain the behavior of the vanilla game as much as possible.

They control two options that can be overridden individually:

  • DistancePathfindingFallbackNodeSelection: Sets how distance pathfinding, i.e. bracken evasion, behaves when it fails to find a valid path out of line of sight, or any other criteria. The default behavior is to only return reachable nodes. This can be changed to behave the same as vanilla, where the path may not be valid, resulting in the enemy stutter stepping towards the evasion node.
  • AsyncDistancePathfindingMostOptimalDistanceBehavior: Determines whether mostOptimalDistance is set to the distance to the chosen node for AI when they are making use of the vanilla async pathfinding solution. Not setting it causes the bracken to stop in front of the player if they spot it within 5 units.

Thanks to

  • Lunxara - Tested the early beta versions that were crashing due to Unity silliness.
  • mattymatty - Brainstormed, assisted in reverse engineering Unity, and helped implementing synchronization to prevent crashes.
  • XuXiaolan - Helped test asynchronous pathfinding by becoming an early adopter of PathfindingLib in CodeRebirth.
  • Zehs - Pointed out the calls to FindObjectsByType<FlowerSnakeEnemy>() that are patched since v2.0.0.
  • qwertyrodrigo - Made this meme: A meme

CHANGELOG

Version 2.1.0

  • Fixed a bug that would cause the bracken not to path out of line of sight in some situations.
  • Added presets and options to configure the bug fixes that slightly change behavior from vanilla.

Version 2.0.1

  • Updated the manifest description to no longer state that it is a beta version.

Version 2.0.0

Note that this has the same mod ID as PathfindingLagFix Beta, but a lower version, so that will need to be disabled in order to run the stable version.

  • Rewrote the mod to run all pathfinding patches off the main thread using PathfindingLib, reducing the performance impact of many forms of vanilla enemy pathfinding to near zero. This provides a general framerate improvement when many enemies are spawned, especially for hosts.
  • All patches have been completely rewritten.
  • Patched behaviors now include:
    • All roaming AI (i.e. thumpers, lootbugs, coilheads, and many more)
    • All omniscient player targeting (i.e. blobs, jesters, brackens, and more)
    • Bracken hunting, evasion, and hiding spot pathfinding
    • Snare flea hiding spot pathfinding
    • Spore lizard evasion pathfinding
    • Tulip snake dismounting pathfinding, and calls to FindObjectsByType<FlowerSnakeEnemy>()
    • Manticoil evasion pathfinding

Version 1.4.0

  • Brought back the patch for lag caused when the Bracken has no player target and is therefore pathing to the furthest position from the interior entrance. This would often occur when the player jumps.

Version 1.3.1

  • Updated mod icon and Thunderstore summary.

Version 1.3.0

  • Updated to support v60/v61, removing patches for the Bracken and Spore Lizard now that vanilla uses an async method for those AI.

Version 1.2.1

  • Removed some debug spam that would happen while a Snare Flea is retreating with no target players.

Version 1.2.0

  • Prevent stutters caused by Snare Fleas finding a far location when there are no players to target.
    • This pathfinding would always happen if a Snare Flea spawned while no players are within the building.
    • More often in normal gameplay, it would occur if the Snare Flea fell off the playable area, since this would make all players untargetable, as well as make the search for a far location eventually fail.
    • NOTE: This may not cover all cases of lag caused by Snare Fleas. When they are running from a kill, they look for the nearest location that is accessible out of line of sight. If all line of sight checks fail, there may be stutters.

Version 1.1.0

  • Fixed stutters that would happen when Spore Lizards run from the player.

Version 1.0.1

  • Removed printing of the FlowermanAI.DoAIInterval() bytecode.

Version 1.0.0

  • Fixed stutters that could occur when Brackens are retreating.
  • Fixed stutters that always occur when Brackens spawn outside or are not on the nav mesh.