Hi, I’m trying to instantiate an object (which has children objects) from prefab, but it only instantiates the parent object, and not the children.

I have two variables

public var TargetIndicator:GameObject;
public var TargetIndicatorPrefab:GameObject;

function Start () {
TargetIndicator = Instantiate(TargetIndicatorPrefab);
}

TargetIndicatorPrefab is assigned the object “TargetIndicatorGO” which has a child TargetIndicator, but when the script runs, it only instantiates “TargetIndicatorGO” with no children.
What am I doing wrong?
Thanks…

You don’t need to use “public” for one, variables are public by default in js. Make the “clone” object (TargetIndicator) private so it doesn’t show in the inspector. If you haven’t done this already, you need to right click in your project pane and choose Create > Prefab. Now drag the SCENE OBJECT onto the PREFAB, and delete the original object from the scene. Now drag your PREFAB onto the slot in the inspector for Target Indicator Prefab.

private var TargetIndicator : GameObject;
var TargetIndicatorPrefab : GameObject;

function Start () 
{
    TargetIndicator = Instantiate(TargetIndicatorPrefab);
}