Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Zergling103 · Apr 14, 2012 at 03:16 AM · editorarrayplayergetcomponentinchildren

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:

http://pastebin.com/aiGpg2qk

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zergling103 · Apr 14, 2012 at 05:33 AM 1
Share

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

avatar image rutter · Apr 14, 2012 at 10:43 PM 0
Share

Good to know. Thanks for posting your solution!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Extend Unity ObjectField / Array function/Gui interface 1 Answer

Vector2 Editor Visualization 2 Answers

Are 32 bit and 64 bit builds of the editor required? 1 Answer

Can a GameObject inside of an array be made "accessible" from the editor? 2 Answers

"add selected" editor script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges