Setting public variables by dragging: diverse results

I am a bit confused about the relation between GameObject instance and the script (class) attached to it; using C#.

In terms of class extension, I believed that there was no relation whatsoever. I have a standard GameObject A with a class attached to it, Aclass. Now say in Aclass I have a bool variable isOn.

Now on the associated class of another GameObject, I have a public variable which is assigned by dragging the prefab A onto it. What happens?

I found out that it depends on the type you assigned to the public variable: if its of type GameObject, Unity assigns it to A, if it is of type Aclass, Unity assigns it to the class associated to A.

Is this the expected behavior? Can anyone point me to specific documentation?

Basically you’ve got it right there.

A reference is typed as the type of the attached script, found from the prefab with GetComponent (effectively) - so if you have a variable of type AClass (derived from Component/Behaviour/MonoBehaviour) then the reference will be to the component attached to the Game Object, but should you instantiate it, then the whole Game Object and all of its other scripts attached in the prefab will be created and the reference to the copied AClass will be returned by the Instantiate call.

If you have GameObject then that is the thing you will get back.

GameObject is almost totally useless from the Unity side of things - it’s basically only function is to allow us to call SetActive and AddComponent. Of course it’s doing a lot of stuff on the C++ side.