"SkinnedModelRenderer.SceneObject is null until the renderer goes live, so a spawn-time CastShadows write no-ops"
▸ SYMPTOM
You spawn NPCs with a shadow toggle set off. You write Flags.CastShadows on each SkinnedModelRenderer at spawn time. The NPCs keep casting shadows anyway.
Nothing errors and nothing warns. An unpredictable subset of the spawned NPCs ends up stuck at the default shadow state. Verified on engine 26.07.22.
▸ CAUSE
SkinnedModelRenderer.SceneObject is null until the renderer first goes live. The shadow flag lives on the SceneObject, so a write at spawn time has nowhere to land.
The write happens before the renderer has a live SceneObject to carry the flag. It does not throw and it does not warn. The value you asked for is simply not the value that lands.
▸ FIX
Do not trust the write. Confirm the state that actually landed and retry until it matches:
- Write
Flags.CastShadowson the renderer as before. - Read the flag back from the renderer, rather than assuming the write took.
- If the read-back does not match the value you intended, write it again on a later frame.
- Stagger the retry across the following frames so a full spawn batch does not re-check on one frame.
- Stop retrying an NPC once its read-back matches the intended value.
Tested A/B at 120 NPCs. A retry-until-confirmed sweep converges every spawned NPC to the intended shadow state. A fire-and-forget spawn-time write leaves an unpredictable subset stuck at the SceneObject's default.
▸ WHY IT WORKS
The read-back reports the state the SceneObject holds now, not the state you requested. So it tells you whether the SceneObject existed yet when you wrote.
Staggering the retry across frames gives each renderer time to go live and gives the batch a frame budget that does not spike. Each NPC drops out of the sweep the moment its live state matches the target.
- Published.