x


BCE0019: 'enabled' is not a member of 'UnityEngine.Component'.

This is for WeaponManager.js error at 'enabled'

function DeselectWeapon(){

//Dectivate all weapon for (var i : int = 0; i < weaponsInUse.length; i++){ weaponsInUse[i].gameObject.SendMessage("Deselect", SendMessageOptions.DontRequireReceiver); var deactivate : Component[] = weaponsInUse[i].gameObject.GetComponentsInChildren(MonoBehaviour); for (var d in deactivate) { var d : MonoBehaviour = d as MonoBehaviour; if (d) d.enabled = false; } weaponsInUse[i].gameObject.SetActiveRecursively(false);

more ▼

asked Aug 04 '12 at 06:36 AM

Xdy gravatar image

Xdy
33 10 18 24

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Change d.enabled to d.gameObject.active or convert it to a GameObject and use d.renderer.enabled.

active is not part of UnityEngine.Object or GameObject. active is to check if is it avaiable/enabled. If you need to check the renderer check gameObject.renderer.enabled.

more ▼

answered Aug 04 '12 at 09:37 AM

drawcode gravatar image

drawcode
246 2 4

That works, thx! how about this similiar but I could not get through error at 'enabled'

function PauseGame() {

savedTimeScale = Time.timeScale;

Time.timeScale = 0;

AudioListener.pause = true;

if (pauseFilter) pauseFilter.enabled = true;

currentPage = Page.Main;

transform.position = new Vector3(0, 1, 0); Screen.lockCursor = false; }

Aug 04 '12 at 10:49 AM Xdy

'enabled' is only a property on some components. Use 'active' is for GameObjects.

'Active' maps to the checkbox in unity whether it is active or not. If you just want to make the item invisible but still there and scriptable/findable you use renderer.enabled usually.

Use .active on GameObjects. .enabled is for some components.

Aug 04 '12 at 07:28 PM drawcode

No, .active is only for GameObjects. .enabled is for all components.

Aug 04 '12 at 07:44 PM Eric5h5

@Eric5h5 only some components have .enabled as it is not part of the base UnityEngine.Object or UnityEngine.Component.

renderer, collider and camera are some that have it.

http://docs.unity3d.com/Documentation/ScriptReference/Component.html

http://docs.unity3d.com/Documentation/ScriptReference/Object.html

http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=enabled

.enabled is available on some components. Joint for instance is a Component that does not: http://docs.unity3d.com/Documentation/ScriptReference/Joint.html

Aug 04 '12 at 09:00 PM drawcode

The point is that .active is only for GameObjects. If you're able to disable/enable a component, it will be with .enabled, not .active. In no case is .active "preferred", nor should .enabled ever be changed to .active. If you try, you'll get a warning specifically telling you not use use .active for components (since that usage was deprecated quite a long time ago). Saying "active is not part of GameObject" is clearly wrong as you can see in the docs.

Aug 04 '12 at 09:55 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x111

asked: Aug 04 '12 at 06:36 AM

Seen: 1570 times

Last Updated: Aug 05 '12 at 06:05 PM