0

In Script Foo, I instantiate prefab Bar which has 3 children. From Script Foo I update a script on each of Bar's 3 children and set their variable X. When debugging I can see that all this is happening correctly.

Script WTF is attached to prefab Bar. From Script Foo, I tell Script WTF to access the scripts attached to Bar's 3 children and get what seem to be 3 new classes where variable X is never set.

I just ran some test and found that from Script WTF:

  • GetComponentsInChildren<TEST>() will return an array with length 0 when it should get 3.
  • GetChild(0).getComponent<TEST>() will return the Script I'm looking for, but Variable X is not set.

This must have something to do with cloning, right?

user3071284
  • 6,955
  • 6
  • 43
  • 57
  • In which function you are calling `GetChild(0).getComponent()`? Have tried changing your codes for example to `update` where everything should be already instantiated for sure. – maZZZu Nov 09 '14 at 21:40

1 Answers1

1

Well... I figured it out. I was checking to see if the prefab existed before instantiating it and so I was also calling methods in the object before it was actually instantiated. It didn't occur to me that loading a prefab and instantiating it are 2 different instances.

  • Congrats. Make sure you accept your answer to let others know your question is solved. Also, had you posted your code, people would have been able to help you. – apxcode Nov 10 '14 at 06:24