Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

-ExampleGameObject
--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.

share|improve this question

2 Answers 2

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

share|improve this answer
    
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. –  Bomadeno Jul 24 '12 at 18:14
    
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. –  Mungoid Jul 24 '12 at 19:04
    
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! –  Bomadeno Jul 25 '12 at 6:39

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 {

    #if UNITY_EDITOR

    void OnDrawGizmos()
    {   
        this.gameObject.SetActiveRecursively(false);
    }

    #endif
}


#endif
share|improve this answer
    
Annoying indeed! Useful code snippet, thanks! –  Bomadeno Jul 24 '12 at 18:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.