Transform.position of object not the same as shown on the inspector

I have an object called “Snake Head” that starts at position (0,1,0) and I want to track it’s position in a script that is assigned to another object. I have this:

121739-help.png

public GameObject object_to_follow;

Debug.Log("Pos1: " + GameObject.Find("Snake Head").transform.position);

Debug.Log("Pos2: " + object_to_follow.transform.position);

With the last 2 lines inside an Update(), the first log gives me the correct and real-time positions of the “Snake Head”, but the second line always prints (0.0,1.0,0.0).

Why is the second line not printing the correct coordinates? What is the most correct way to do this?

Are you sure there aren’t any other objects named “Snake Head”?
Try this solution:

GameObject objectToBeFollowed;

void Start(){
    objectToBeFollowed = GameObject.Find("Snake Head")
}