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:

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. :wink:

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.