- Home /
GetComponentsInChildren() works in the Editor, but not in the Player?
EDIT: Problem (now resolved) was caused by use of GameObject.isStatic in non-editor code. isStatic is an editor-only variable.
Hi,
A really strange bug I found with this function.
In the Editor,
LODGroupScriptable[] meshRenderers = gameobj.GetComponentsInChildren< LODGroupScriptable>();
returns an array with one or more elements.
In the Player, however, that same line of code returns a non-null array with 0 elements.
LODGroupScriptable is a component I wrote; it uses System.Collections.Generic and System.Linq.
This is the code in question:
Answer by rutter · Apr 14, 2012 at 05:05 AM
Implies the call isn't finding those components. Strange. If you haven't already, it's a good idea to check the editor log for build warnings/errors, and to try a development build with script debugging to check for any logged runtime warnings/errors.
And, since it is always important to cover your bases, make doubly sure that those components are definitely attached to the objects in question. ;)
You might check your player settings for the API compatibility level. Linq might not be included in the built player if the setting is very low. Some of the more restrictive platforms may not support it at all (mobile devices, web, and probably now Flash all have their quirks). I'd anticipate you'd be able to catch such a problem earlier on, like at build time, but it does come to mind as a possible sticking point.
See this forum thread for some kinda related discussion.
Never $$anonymous$$d - the problem wasn't actually that at all. It turns out my code had used the Editor-only variable "isStatic" in this combine mesh script. A condition in generating combined LODGroupScriptable's was the objects it'd combine were static (isStatic == true). Since this variable isn't used in the Player, that condition would never be met. Thus, it'd not generate the LODGroupScriptable's at all and they'd never be found.
In short, the moral of the story is: DON'T USE isStatic FOR ANYTHING!!! (Except editor classes.) :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613070314im_/https://answers.unity.com/themes/thub/images/avi.jpg)