- Home /
Is component.enabled Deprecated? Did it ever exist?
In fact, did Component.enabled ever exist?
Is it deprecated or not, does anyone know?
In the Editor when you toggle a component on and off, what are you doing? Or, is it the case that (in fact) you can only toggle-on-and-off the, err, 20 or so derived which do have .enabled which appear in a list like this: http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=enabled
(Note that notably, Monobehaviour does have enabled, which as far as I know turns on and off the Update() function.)
So again in short ... did component.enabled (as such) ever exist?
Actually Component does not have an enabled flag. The Behaviour class, which is derived from Component, introduces the enabled flag. $$anonymous$$onobehaviour is derived from Behaviour. To the best of my knowledge, it is not depreciated, but I'm not the authority.
Robert - do you happen to know, did component (itself) EVER HAD an enabled flag? Perhaps that's my basic confusion and idiocy here. Thank you so much.
Answer by Bunny83 · Sep 25, 2013 at 08:36 AM
The component class itself never had an enabled property. A lot other built in components have their "own" enabled property, like Renderer, Collider, ParticleEmitter, .... Those "enabled" properties have nothing in common except the name. In other words there's no way to use some kind of base class to handle them all since they aren't related (in the sense of inheritance)
Answer by robhuhn · Sep 25, 2013 at 08:04 AM
enabled is not deprecated. In Unity 4 they only changed the active handling:
GameObject.active and GameObject.SetActiveRecursively() have been deprecated. Instead, you should now use the GameObject.activeSelf and GameObject.activeInHierarchy getters and the GameObject.SetActive() method.
You would still use enabled to enable and disable { items such as behaviours, as @robertbu said } [Ed: I slightly changed this sentence to avoid mass confusion! :) ]
@rob, thanks
(1) enabled is not just available on "Behaviour". It seems to be available on a randomly-unconneted list of items, for example click here to see some (but not all) of them:
http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=enabled
(2) Rob I'm thinking the question becomes more specifically: was enabled ever available on component as such? or do I just have my head in ass as usual there? Do you happen to know?
(I thought it was once on "component" generally, and then they moved it down only to that "specific list of stuff" -- but maybe I'm plain totally wrong and it was only ever on that specific list of stuff... thoughts??)
thanks!!
1) Yes, it's not only available on behaviour because enabled is just a name for a property. This enabled and that enabled do different things - Just like Task.IsRunning and Human.IsRunning where the names are equal but the context is different. I guess I get you wrong somehow.
2) I don't know if it was a property of component in the past and actually I'm wondering why that's important because in any way you wouldn't need to refactor your code.
Fattie was talking about other components, not about arbitrary classes with enabled ;). A common usecase would be to disable all components on a gameobject. However since Component doesn't have an enabled property you can't do this.
Of course there are components that can't be disabled (since it wouldn't make any sense like the Transform)
(1) - totally got it now, thanks. indeed it's "just the same word". absolutely no OO-esque relationship
(2) well, I wanted to know if it ever was on component generally (answer - absolutely not) and I wanted to know how or if it at all it could be generalised (was there some thing X that all X has "enabled" - answer, absolutely not, it is sheer homograph.)
{I would possibly feel that, in program$$anonymous$$g, especially such a big API like Unity, it is a poor idea to have such a wholly-pro$$anonymous$$ent homograph, that has utterly no meaning whatsoever. I bet 95% of programmers from $$anonymous$$ars, glancing at slabs of Unity code, would assume that is an actual inherited property [perhaps from Component or Behaviour or even GameObject] rather than a pure utterly meaningless coincidental homograph. Anyway that's not relevant.}
Again thank you so much for the superb insight and explanation, cheers
{Thus for example: you can find literally 100s of examples on this site or the internet, where, programmers either think that "enabled" is a property of something like Component, GameObject or Behaviour, and additionally generally confuse it with say SetActive (which relates only to gameobjects of course). Glancing around the internet, this confusion is very common, if not ubiquitous. Note too that in the inspector the checkbox for GameObject feels similar to the homograph-utterly-coincidental-no-relationship-in-any-way-amongst-themselves-"enabled"-checkboxes. So, it's clearly a topic ripe for confusion.}
{I personally had no clue, whatsoever, about any of this - at all. I would just thrash around clicking boxes, or in code randomly change between enabled, setActive, etc etc, until it seems to work and a client sends money :O Now, all is totally clear.}
In a word this question would probably be useful to many - now everyone will have the understanding you three guys already exhibit!