Custom Asteroids

Custom Asteroids

21.6k Downloads

FixedRateSpawner initialization problems

Starstrider42 opened this issue ยท 1 comments

commented

Background Info

  • Operating System: Windows 10
  • KSP Version: 1.6.0
  • Custom Asteroids Version: Post-1.5.0 dev build

Issue Description

When a save game is first loaded and the FixedRateSpawner boots up, it thinks it is UT 0. This causes the spawner to quickly recreate all asteroids that would have spawned between UT 0 and the true in-game date. While these asteroids get cleaned up (they're mistaken for stock-spawned asteroids), this slows down game loading. Note that this bug only happens when a save game is loaded, not during scene changes.

Unfortunately, a naive fix to this problem runs into a much worse bug, where each scene change resets the Unity random number generator to a fixed value (related to #1?). The result is that identical asteroids are produced after each scene change. This doesn't seem to happen when Custom Asteroids is not installed or when FixedRateSpawner is allowed to spam asteroids, for reasons unknown.

commented

The fix to #45 involved rewriting FixedRateSpawner almost from scratch. While the new implementation might also be initialized with UT 0, it cannot spawn more than one asteroid per tick, causing minimal slowdown. I've also confirmed that this fix does not create duplicate asteroids in the sense described here or in #39.