Author Topic: GetComponentInChildren<Transform> returns no results on Unity 4  (Read 6274 times)

athos

  • Guest
GetComponentInChildren<Transform> returns no results on Unity 4
« on: November 30, 2012, 07:52:00 PM »
I noticed on some of my prefabs that after I upgraded to Unity 4 this stopped working and no longer returns results:
transform.GetComponentInChildren<Transform>()

I see that UIButtonMessage relies on this, so you might want to just double check to see if you're seeing the same.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GetComponentInChildren<Transform> returns no results on Unity 4
« Reply #1 on: December 01, 2012, 11:31:44 AM »
GetComponentsInChildren() will only return components on active game objects. That is -- if a game object is disabled -- the component will not be returned. The way UIButtonMessage works is correct: there is no sense in sending messages to components on disabled game objects.

athos

  • Guest
Re: GetComponentInChildren<Transform> returns no results on Unity 4
« Reply #2 on: December 01, 2012, 07:08:01 PM »
Ah, that's what I'm seeing here. Thanks for the tip!