'tag' is not a member of UnityEngine.Object

Hi,

i just tried to build my game for some testing and this error appeared: " ‘tag’ is not a member of UnityEngine.Object ". Without solving that i can’t do anything.
I looked up online, and there was some talk that it’s not possible to tag GameObject (array) ?
This is a simple script for instantiating objects:

Obj1 = Instantiate(obj1, pos1.position, pos1.rotation);
Obj1.tag = "spawned";

Do you now what can be the problem?

Thanks

Instantiate returns an object. If the variable you cast it to (Obj1) is explicitly defined as the correct type unitys javascript fill fix it behind the scenes, but if both are not explicitly defined Instantiate will return an Object and Obj will be assumed to be an Object as well. You want Obj1 to be a gameObject, wich has the class variable tag.

You want Obj1 to be a gameObject. So either correctly define it as such:

var Obj1 : GameObject = Instantiate( obj1, pos1.position, pos1.rotation );

Or, even better, don’t let the compiler fix it behind the scenes but fix it explicitly.

var Obj1 : GameObject = Instantiate( obj1, pos1.position, pos1.rotation ) as GameObject;