- Home /
SetActive in Editor script strange behaviour
Hello,
I have an editor script in which I automatically configure a scene each time I receive a new version from my 3D artist. It contains 100s of objects that need to be configured by adding scripts and filling the scripts with data stored in scriptable objects. This works fine. But I also need to enable/disable specific game objects. And there things are going strange.
Here part of my code:
GameObject[] objects = Resources.FindObjectsOfTypeAll<GameObject>();
foreach (GameObject o in objects)
{
// Do stuff
// TEST SETACTIVE
if (o.name == "KetelVervangen_01")
{
string objectType = "";
if (PrefabUtility.GetPrefabParent(o.gameObject) == null)
objectType = "Prefab: ";
else
objectType = "GO in hierachy: ";
Debug.Log(objectType + o.activeSelf);
o.gameObject.SetActive(true); // THIS IS NOT WORKING AS EXPECTED
Debug.Log(objectType + o.activeSelf);
}
}
The output of my "Test SetActive" block (where I test 1 of 100s objects) is: - Prefab: True - Prefab: True - GO in hierarchy: False - GO in hierarchy: True
So it seems that, based on the activeSelf property, SetActive is actually doing it's thing, but my game object in the hierarchy itself stays inactive.
Any clues?
Answer by dk1 · Jul 27, 2016 at 04:57 PM
Just adding a note, a deactivated object doesn't seem to be able to activate itself. Try activating from its (active) parent.
Your answer
