How to find `Vector3` of another GameObject

Hello, I need to use Vector3.Distance to create a targeting system. However the Vector3 A will not work because of my method of referencing it. I use GetComponent, but it appears that does not work, after all Vectors are not components. Whoops. So how do you find the Vector 3 of another object?
Here is my current code:

Player = GameObject.Find("Player").GetComponent<Vector3>();

I know I need to do away with GetComponent, but what do I use in it’s place?
Thanks in advance.

Review the Transform class reference (Unity - Scripting API: Transform). Observe each game object in Inspector. The first component is always the Transform component. There is no Vector3 component. The position you’re looking for is a property of the Transform component. Your code needs to say “Get the transform component and then get the position property of it”:

Example: If Player is a Vector3 variable…

Player = GameObject.Find("Player").GetComponent<Transform>().position;

This will store the current position (this frame only) of the Player, but there are several things that may cause problems with this approach.

  1. If some other object is searching for Player’s position, it likely needs to respond to that Player in some way as the position changes, which means you’d have to call this code over and over in Update(). That should be avoided, since GameObject.Find() is a fairly expensive operation. Instead, if this other object absolutely needs to track player’s movement, it can cache the player’s Transform object directly, once only in Awake(), Start(), or OnEnable(), in a variable called playerTransform or whatever you like. Then, you can grab player’s position during Update() using playerTransform.position.

  2. Generally, if any object is tracking player movement in real time, you’ll typically have a lot of hard-coded dependencies. Those other objects are usually enenmies, NPCs, or interactable objects. In any case, those objects must maintain a hard reference to the player object, which now requires the player to be instantiated (or null refs fill your console), which means you can’t unit test other aspects of those objects in a sandbox easily.

Instead of hard refs from other-to-player via GameObject.Find(), I recommend broadcasting events from player to listeners. See UnityEvent (Unity - Scripting API: UnityEvent), and research “event system in Unity” on Youtube.