NullReferenceException: Object reference not set to an instance of an object

Hello Guys’

I have this code:

public var gObj : GameObject;

function Create() {
var obj;
obj = new OBJ(); //Creates a model and it has a GameObject member.

gObj = obj.obj;

Debug.Log("bounds: " + gObj.GetComponent(MeshFilter).bounds);

}

ok so gObj is GameObject and I make the assignment of obj.obj that I am sure is of the same type. When I call Debug.Log I try to access the component but I get a NullReferenceException message… and I don’t quite understand why :frowning:

thanks.
Giancarlo

Are you sure the GameObject assigned to your “obj.obj” has a MeshFilter assigned to it? Beyond that, can you double-check that the code you omitted with the “…” never reassigns null back to gObj (or your code elsewhere in the system assigns it back to null)?