In a script in Object A I do the following:
var prefab : GameObject;
var myObj : CustomGameObject;
var temp : GameObject = Instantiate (prefab, transform.position , transform.rotation);
We'll call the instantiated gameObject Object B. In Object B's Awake function I do this:
childObj = new ChildCustomGameObject(gameObject);
ChildCustomGameObject extends CustomGameObject, both are declared in another file. Now in Object A, immediately after Instantiating Object B, I want to say myObj = childObj. But I want to do this without having to actually know the name of the script attached to Object B, nor the name of the derived class of CustomGameObject. I figured SendMessage was perfect, so I tried this in Object A:
temp.SendMessage("GetCustomObject", myObj)
Which called in Object B:
function GetCustomObject(obj : CustomGameObject)
{
obj = childObj;
}
But it doesn't work. When I look at Object A's myObj in the inspector, it looks like it created its own instance of CustomGameObject, and all the properties inside it are null.
So how can I get myObj from Object A to be a pointer/reference to a class rather than a instance of a class? And how can I get it to point to childObj from Object B? Is this possible in Javascript?