I am quite new to Unity and after playing around with some stuff, I have a small problem. Let’s say I create an empty GameObject and add some objects to it. For example I can have a GameObject, or Prefab called PlayerCharacter, which contains 3 objects:
Model
SpellSpawnpoint
Camera
Now I add a script to PlayerCharacter, for example one creating spells. I need to access SpellSpawnpoint object to instantiate spell, but… how?
Which is another solution, but if I had to guess at the implementation of that method, it's searches the entire scene graph for it; albeit cleaner than mine, I'd be nervous about performance depending how the frequency in which it's called.
He's looking for the sub gameObject though, not the component. Although, my guess is that he's looking to ultimately end up at some component ;)
– YokimatoIf he just wants to find the game object, how about: [Transform.Find()][1] [1]: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Find.html
– robertbuWhich is another solution, but if I had to guess at the implementation of that method, it's searches the entire scene graph for it; albeit cleaner than mine, I'd be nervous about performance depending how the frequency in which it's called.
– YokimatoIt does not search the entire scene. It's an instance, not a class method, so it only searches from the given transform.
– robertbu