Skip to content

Conversation

@DanyilYedelkin
Copy link

@DanyilYedelkin DanyilYedelkin commented Oct 25, 2025

Fix: #2768 — Touch spell
Fix: #2767 — WeaponManager hit detection issues
Perf: Optimized DaggerfallMissile runtime (GC + CPU improvements)

Bug Fixes

Optimization

  • Replaced Physics.OverlapSphere() + new List<> with Physics.OverlapSphereNonAlloc() and a reusable buffer to eliminate heap allocations during AoE checks.
  • Cached references to GameManager, WeaponManager, and frequently used components (Collider, EnemySenses, EnemyAttack, CharacterController) to reduce expensive GetComponent<T>() and singleton lookups.

Impact

  • Fixes inconsistent spell and melee hit detection.
  • Eliminates GC spikes and microstutters during combat.
  • Reduces CPU cost per missile instance, improving performance in large fights.

Verification

  • Tested touch spells, melee attacks, and AoE effects on multiple enemies.
  • Verified consistent hit registration and unchanged gameplay behavior.

fixed bugs with "Touch spell hit detection targets the player when aiming downwards" and "WeaponManager attack raycast layer mask collides with objects on the "Ignore Raycasts" layer"
### Summary
This PR improves runtime performance of DaggerfallMissile by reducing GC allocations and minimizing Unity API overhead.

### Changes
- Replaced `Physics.OverlapSphere()` + new `List<>` with `Physics.OverlapSphereNonAlloc()` and a reusable buffer to prevent per-frame heap allocations during AoE checks.
- Cached references to `GameManager`, `WeaponManager`, and frequently used components (`Collider`, `EnemySenses`, `EnemyAttack`, `CharacterController`) to reduce expensive `GetComponent<T>()` and singleton lookups.

### Impact
- Eliminates GC spikes and microstutters during large-scale spell effects (fireballs, explosions, etc.).
- Reduces CPU cost per missile instance, improving scalability in combat-heavy scenes.

### Verification
- Tested AoE spells and ranged projectiles with multiple active missiles.
- No change in gameplay behavior; only internal performance improvements.
@DanyilYedelkin DanyilYedelkin changed the title #2768 and #2767 (fixed bugs) #2768 and #2767 (fixed bugs) and some optimization Oct 27, 2025
using DaggerfallWorkshop.Utility;
using DaggerfallWorkshop.Game.MagicAndEffects;
using DaggerfallWorkshop.Game.Entity;
using System.Runtime.InteropServices;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, what is this used for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops... Sorry, I forgot to remove that. I needed it for some other tests... It’s gone now

Removed unused 'System.Runtime.InteropServices' namespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants