Skip to content

fix(timing): don't apply physics mode to project settings from OnValidate - #1077

Open
ddelgado95 wants to merge 1 commit into
FirstGearGames:mainfrom
ddelgado95:fix/timemanager-onvalidate-project-settings
Open

ddelgado95 wants to merge 1 commit into
FirstGearGames:mainfrom
ddelgado95:fix/timemanager-onvalidate-project-settings

Conversation

@ddelgado95

Copy link
Copy Markdown
Contributor

Problem

TimeManager.OnValidate calls SetInitialValues(), which runs InitializePhysicsMode. With PhysicsMode.TimeManager that sets Time.fixedDeltaTime = TickDelta and Physics.simulationMode = SimulationMode.Script (and the 2D equivalent).

Outside play mode those properties are the project settings. OnValidate runs whenever the component is loaded in the editor (opening a scene containing the NetworkManager, touching its inspector, or the build pipeline processing that scene), so the values leak into:

  • Project Settings: Physics → Simulation Mode becomes Script and Time → Fixed Timestep becomes 1 / TickRate. Both are written to DynamicsManager.asset / TimeManager.asset on the next save.
  • Player builds: the build uses the in-memory settings, so a player built after the scene is loaded ships with Script physics and a 1 / TickRate timestep, whatever the project files say.
  • The saved "user" timestep: InitializePhysicsMode stores the current Time.fixedDeltaTime in PlayerPrefs (SavedFixedTimeFN) before overriding it. After the first OnValidate override, every later call stores TickDelta as the user's value, so exiting play mode can never restore the real setting.

Repro

  1. Project Settings: Simulation Mode Fixed Update, Fixed Timestep 0.02.
  2. In edit mode, open a scene with a NetworkManager whose TimeManager uses PhysicsMode.TimeManager (tick rate 30).
  3. Project Settings now show Script and 0.0333.
  4. Build a player: at startup, before any NetworkManager exists, Physics.simulationMode == Script and Time.fixedDeltaTime == 0.0333.

In our project, physics never stepped in scenes without a NetworkManager. Trigger-based interactables in the main menu never fired, even though the project files said Fixed Update.

Fix

OnValidate now returns early outside play mode. The inspector reads the serialized _tickRate directly, and TickDelta / _adjustedTickDelta are only read at runtime, after InitializeOnce_Internal → SetInitialValues has set them. During play OnValidate still re-applies everything, so play-mode behaviour is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant