If I create a simple object hierarchy in my scene...

--Child1 [is active]
--Child2 [is not active]

...how can I accurately store this as a prefab? If I drag ExampleGameObject to a new prefab, then instantiate that prefab, both Child1 and Child2 will be active, which isn't what I want.

  • 3
    \$\begingroup\$ I'm voting to close this question as off-topic because it's no longer reproducible in recent versions of Unity (4.x & 5.x). Simply changing the enabled state of a child object and updating the prefab correctly sets the state of that child when the prefab is instantiated. I recommend closing this question because without an accepted answer, the community user will keep bumping it to the front page, even though it's no longer relevant. \$\endgroup\$
    – DMGregory
    Commented Feb 18, 2017 at 1:58
  • \$\begingroup\$ @DMGregory I'm not sure there is an 'obsolete' close reason; maybe a mod could give the appropriate close reason when closing it, though! \$\endgroup\$
    – Vaillancourt
    Commented Feb 18, 2017 at 13:20
  • \$\begingroup\$ @AlexandreVaillancourt I could only find one oblique reference to this type of situation on Meta, from Josh Petrie: "In the cases where the question itself can become outdated to the point of non-usefulness, I still mainly [think] that's a case for closing due to the topic being too localized" \$\endgroup\$
    – DMGregory
    Commented Feb 18, 2017 at 16:01

3 Answers 3


Annoyingly, the simplest way is to attach a script to one of the prefab GameObjects that set the enabled flag manually when the object is dropped into the editor.

using UnityEngine;
using System.Collections;

#pragma strict

public class SetInactive : MonoBehaviour {


    void OnDrawGizmos()



You need to instantiate the Prefab while the Child is active, assign it to a variable and then set the Child inactive.

Otherwise there is no way to activate the Child since you can't assign a Prefab component to a variable before Instantiate to reach it later, and also you can't "Find" an inactive GameObject to make it active. Either way you won't be able to get any reference to activate a disabled Child in a Prefab.

Pseudo Unity 3D C# code:

Define a variable in a script attached to the main component of the prefab:

public class MyPrefab {
    public GameObject problemChild;

In your game code, while instantiating that prefab assign the child to the variable in the prefab and then disable the child:

Transform newTransform;

void InstantiateMyPrefab() {
    newTransform = Instantiate(myPrefab, position);
    newTransform.problemChild = newTransform.FindChild("ProblemChild").gameObject;

So it will be instantiated with the child disabled by default and you'll have a reference to that child.

Later in the game you can call this to make the child active again.

void WhereIsMyChild() {

Yes you can! If you uncheck the checkmark next to the name of the game object that you want disabled in the inspector. There is also a way to do it via code without checking, i think you just call the gameObject you want to be disabled and set .active to false

enter image description here

  • \$\begingroup\$ This doesn't answer my question - try my scenario, create a prefab and drag on the ExampleGameObject. When you create a new instance of the prefab, both objects will be enabled. \$\endgroup\$
    – Matt Bond
    Commented Jul 24, 2012 at 18:14
  • \$\begingroup\$ Im not exactly sure if this helps any but you could try and uncheck the mesh renderer for object in the prefab. Its technically still there, just not being displayed though. \$\endgroup\$
    – Mungoid
    Commented Jul 24, 2012 at 19:04
  • \$\begingroup\$ This was my 'resort to' option, it's alright in isolation, but clutters my calling code. (I have an "enable object" script, which is used often, a generic "enable x component in object" script would be either time consuming or messy) Good advice for the times it's unavoidable though! \$\endgroup\$
    – Matt Bond
    Commented Jul 25, 2012 at 6:39
  • \$\begingroup\$ OnEnable() is not being called after calling .SetActive(true). Any idea? \$\endgroup\$ Commented Aug 20, 2014 at 8:18
  • \$\begingroup\$ In this case there is no way to re-activate the child because you can't "Find" an inactive child or assign a Prefab component to a variable before Instantiate, which means you won't have any reference to activate a disabled Child in a Prefab. \$\endgroup\$ Commented Feb 17, 2017 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .