Can't retrieve information from GameObject

Good afternoon.

I’m currently having trouble trying to retrieve information from a gameObject. And maybe there’s a workaround what I’m doing while using another more-db-like-approach, which would appreciate very much.

Trouble is, I have the following JS:

var Realname: String;
var description: String;
var price: float;

That JS is assigned to a prefab (gameObject).

Now I have another JS :

var currentObject : GameObject;
function Start () {

After I assign the prefab to currentObject in the inspector , my debug.log results are:

  1. prefab name (not the Realname var)

  2. NULL

Any ideas?

Thanks a bunch.

You would have to access the Realname variable in your other JS script.


If this initially gives you an error it’s probably because the Realname variable is not accessible from the other script, you could change this by saying:

public var Realname: String;

when you create it, or a better way is to create a getter function in your first script, outside of any other functions that returns Realname:

public function GetRealName(){
return Realname;

and then call that from the second script where you want to get it:


The second way is the better way when it comes to security and proper coding techniques.

Hi, GameObject itself does not contain those values, GameObject contains scripts and scripts contain it.
Use getcomponent to access others scripts.
I explained it ver clearly in this answer: Transform var between scripts - Unity Answers
There’s an example in c# and unityscript.

Also dont forget to drag and drop the go on the public variable.