GameObject Oooops.

Hey guys, I have a question about a game object that I define in a script like I normally do. BUT when I want to assign any object that is in the hierarchy computer says no. I can however assign objects that are not in the project tab. Why is this?

What, precisely, does your computer say? :slight_smile:

Also, are you assigning these references to variables in scripts associated with prefabs, or with other game objects in the scene?

Thanks for responding Jesse. My computer doesn’t actually say anything it just does not allow me to add any object from the Hierarchy. It lets me add objects from the Project tab though. Very strange.

var boneAttach : GameObject;

function Update () 
{
	transform.position = boneAttach.transform.position;
	transform.rotation.x -= 0.01 * Time.deltaTime;
	transform.localScale += Vector3( 0.01, 0.01, 0.01 );
}

What I desire to happen here is for the laser beam to attach itself to the an eye bone and move with the animation.:smile: Thanks for you help!

Prefabs are universal and don’t have any ties to any scene, therefore it’s impossible to make a prefab reference a hierarchy object, because a hierarchy object only belongs to one scene. You can make a prefab instance in a scene reference anything though, because then it’s an instance and part of the scene.

–Eric

I don’t think you can assign references to scene objects to variables in scripts associated with prefabs. (Remember, prefabs exist outside the scope of any one particular scene. If you instantiated an object from that prefab in a different scene, the object it referenced wouldn’t even exist at that time, so what would the reference point to?)

As for how best to solve the problem in question, I’m not sure (as the solution will likely be context-dependent).

[Edit: Foiled.]

Oh wow great answers guys. Thank you very much for your help. I though about assigning the bone of my model from its prefab but you do not have access to them unless they are in the hierarchy HAHAHAHA. So the hack that I have devised and shall try in a moments time will to have a node prefab that I may assign then attach it to the bone in the scene when the game runs and THEN uhhhggggg… the laser will attach itself to that node prefab. WEEEEEeeee. Cheers M8s