5/29/2023 0 Comments Unity3d gameobject find inactiveThe first array includes only SpriteRenderers on active GameObjects, the second includes both those on active and inactive GameObjects, and the third uses System.Linq to only include those on inactive GameObjects.įor newer Unity versions this answer provides probably a better solution! SpriteRenderer onlyInactive = GameObject.FindObjectsOfType(true).Where(sr => !sr.gameObject.activeInHierarchy).ToArray() SpriteRenderer activeAndInactive = GameObject.FindObjectsOfType(true) The following code requires System.Linq: SpriteRenderer onlyActive = GameObject.FindObjectsOfType() Therefore, just use it like you regularly would, but also pass in true. Objects attached to inactive GameObjects are only included if inactiveObjects is set to true. To find an object of a certain type whether it's on an active or inactive GameObject, you can use FindObjectsOfType(true) In the years since this question was asked, Unity put in the exact thing you need.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |