Fixing ancient library: does .active default to activeSelf or activeInHierarchy?

I understand the difference between activeSelf and activeInHierarchy, and most threads revolve around that.

Hoverer I’m trying to remove warnings from a library I’m using, so I do not know what’s going on there. I only know that it’s using .active and that it works, so I’m wondering what .active defaults to, in order to replace it.

Should I replace it with .activeSelf or with .activeInHierarchy?

No guesses please, it must default to something and I’d like to know just that.

@Fattie I'm sorry, I do not want to sound rude, but apparently you just didn't read the question and gave a default answer. Try actually reading it, please. (again, sorry if it sounds rude, I didn't mean to, but I honestly do not know how to say such a thing more politely. Just pretend it is ;))

Thanks for pointing that out, it's entirely my mistake. Note that I never, ever read all of a question. You did not in the slightest sound rude. Nice investigation for anyone fooling with old code, good one.

1 Answer

1

I’ve built a test scene, and apparently it defaults to activeInHierarchy, which makes perfect sense.

Here’s the code:

using UnityEngine;
using System.Collections;

public class ActiveTest : MonoBehaviour {
	public ActiveTest[] children;
	public bool testOnAwake;

	public void Awake () {
		if (testOnAwake) {
			Debug.Log(this.name+": testing "+children.Length+" child(ren)");
			TestChildren();
		}
	}

	public void TestChildren () {
		foreach (ActiveTest test in children) {
			test.TestSelf();
		}
	}

	public void TestSelf () {
		Debug.Log(this.name+": active="+gameObject.active+", activeSelf="+gameObject.activeSelf+", activeInHierarchy="+gameObject.activeInHierarchy);
	}
}

Ideally do not use the library, since it is using deprecated calls. A very dangerous business. .active. It is deprecated. Use the new facilities now available. It is explained at incredible length here: http://docs.unity3d.com/Documentation/Manual/UpgradeGuide3540.html #"the GameObject.active property [ ] has been deprecated."