Cant get position of parent gameobject;

Hello, i have this code.
item is a child of parent.

                parentobj = item.transform.parent.gameObject;
                target = parentobj.transform.position;

And unity says null reference at line

parent = item.transform.parent.gameObject;

Nvm i didnt referenced item gameobject before

Please flair your post as RESOLVED.

The answer is always the same… ALWAYS!

How to fix a NullReferenceException error

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

NullReference is the single most common error while programming. Fixing it is always the same.

Some notes on how to fix a NullReferenceException error in Unity3D:

http://plbm.com/?p=221