"Bind lazily to a component created in OnStart, not from your own OnStart"
▸ SYMPTOM
- A component resolves a dependency inside its own
OnStartand binds to null, even though the dependency does get created during the same startup. - The feature that needs the dependency does nothing for the whole session, while every part it depends on works on its own.
- The only signal is one warning line at the top of the log. There is no exception and no repeated error, so the feature reads as inert rather than misbound.
▸ CAUSE
Two components run OnStart in the same startup. One component creates the target inside its own OnStart. The other component looks the target up inside its own OnStart and binds to it.
Authored beside is not authored before. When the binder runs, the target has been asked for and not yet built, so the lookup returns null. The binder keeps that null for the rest of the session.
OnStart order across separately authored components is not a creation order you can bind against. A component created in one OnStart does not exist yet for anything else's OnStart.
▸ FIX
Bind lazily. Resolve the target when it is created, not when your own component is authored.
- Poll for the target on a short interval, for example every 0.25 s.
- Stop as soon as the lookup returns the component and cache it.
- Warn once if the target never resolves before a deadline.
That is about four lines. It removes a whole class of start-order coupling, because the bind now waits on the target's existence instead of on OnStart ordering.
▸ WHY IT WORKS
A component created inside an OnStart is not visible to any other component's OnStart, so a bind made there reads a world where the target has been requested and not yet built. The lazy retry moves the bind off the authoring order and onto the target's creation, which is the fact you actually depend on.
This is a different failure from sync-component-after-networkspawn-never-pairs, where [Sync] state misses the spawn snapshot. The underlying ordering fact is the same: an OnStart-created component does not exist yet for anything else's OnStart.
- Published