Deactivating a child?

I know this should be simple, but nothing I’ve tried seems to work, so I’m missing something. I’ve got a prefab called “Beacon_Player” that is a child of my player prefab. At a certain point I want to deactivate it through a script on the player, so I’ve got this:

var beacon : Transform;

function Awake() {
    if(networkView.isMine){
    	myBeacon = beacon;
    	myBeacon.enabled = false;
}
}

I’ve assigned “Beacon_Player” to this in the prefab, but I get the following error:

MissingFieldException: Field ‘UnityEngine.Transform.enabled’ not found.

I’ve also tried this with “GameObject” instead of “Transform” and get:

MissingFieldException: Field ‘UnityEngine.GameObject.enabled’ not found.

Any ideas on what I’m overlooking? I’ve also tried variations of GetComponentInChildren and transform.Find(), but also with no luck.

whats MyBeacon?

Do you want to deactivate a game object (gameObject.active = false) or disable a component (component.enabled = false)?

Lots of other potential issues, but that might be the first question to answer.

@ jlcnz: myBeacon is just a variable within the function that I’m setting beacon to. I know that sometimes that’s needed within a function, but I’m never sure when. I tried it both that way and just “beacon.enabled = false;”.

@JohnnyA: I’m trying to deactivate the whole gameObject child. Ie: the enable checkbox next to the name, if that helps. it’s a transform with a bunch of components added to it, but no children underneath it, so I’d rather deactivate the whole thing rather than each of the individual components.

… so maybe for a start you should be using active on the gameObject not enabled on the component …

Aha! That did it. I wouldn’t have even thought of looking at active because I’m so used to just dealing with enabled on components.

Thanks :slight_smile:

That was in the docs.

Yes, it was, and I did search there first, along with these forums and the unify answers site, but the docs don’t always do much good if you don’t know what you are searching for. After I had satisfied myself that I did everything reasonable to find my own answer, I turned to here for a nudge in the right direction, and I’m very grateful for the responses I got. I believe this is the main reason why most people post here.

Please also keep in mind that although the information being sought is often in the Unity docs, they are not the friendliest of sources: the scripting reference is searchable, but that only really helps if you already know what you are looking for and just need to know things like syntax. The examples are atrociously simple and out-of-touch with “real-world” needs or are completely non-existant. The manual and reference docs are even worse in that they are not even searchable. Short of reading them cover-to-cover, they are of limited value other than as a general guide.

I do keep going over them section-by-section, but there are a lot of pieces to the Unity puzzle, and a lot of times there is one simple missing piece such as this that is preventing me from unlocking others. This is such an open system that there’s no way I’m ever going to know everything about it, but hopefully as I learn more and more my questions will become less and less. I doubt I’ll ever stop asking questions, so the ony thing I can hope to do is to learn from each answer and never ask the same question twice.

Once again, I’m grateful that there are those that are more knowledgeable and experienced than I am that are willing to take the time to try to bring me up to their level. Hopefully someday I can do the same for others.