1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Reddit AMA with Adam Myhill on Cinemachine, Thurs July 27 - 10AM PT. More info.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  7. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Add a child to a game object in a script

Discussion in 'Scripting' started by Maelstroms, Nov 26, 2009.

  1. Maelstroms

    Maelstroms

    Joined:
    Nov 26, 2009
    Posts:
    11
    Heya,

    I'm just getting started with Unity, and it looks great so far. However, i'm struggling to do something that should be quite simple to do (it's prolly just me being a failure :)) :

    Let's say I have a GameObject, called "Group" with a script assigned (or an instance of a prefab with just a script in it). What i want to do is to add a child to the Group (a child in the Hierarchy, not a Component) within my Start() function in the script.

    When i tried to use Instanciate() to create a new object in my scene, it just puts it at the root of the Hierarchy, couldn't find a way to add it as a child of Group.

    Any clues ?

    Thanks in advance,

    Mael.
     
  2. kirsis

    kirsis

    Joined:
    Nov 19, 2009
    Posts:
    31
    hersgory likes this.
  3. Maelstroms

    Maelstroms

    Joined:
    Nov 26, 2009
    Posts:
    11
    Aah cheers mate, it works :) Issue fixed !