How to access position of prefab in the Game Object field?

Hey :slight_smile:
So I declared 2 public variables “selectedBaseTower” & “selectedTargetTower” in the gameManager, they are initially empty, when I click a game object with the tag “tower” .Then the game object (the tower) is affected in the field of “selectedBaseTower” or “selectedtargettower” (that’s working perfectly as I wanted) .

The problem is when I want to use the tower prefab position, I can’t access it by using this line of code, I get the position of the GameManager which holds the 2 variables and not the position of the prefabs in the field

Vector3 spawnPosition = new Vector3(selectedBaseTower.transform.position.x, selectedBaseTower.transform.position.y, selectedBaseTower.transform.position.z);

That’s because the position of the Prefab never changes.
Prefabs are just templates, what’s in your scene are GameObjects at least the way you worded your question, the problem is that you are using the position of the prefab which will not reflect the position of the gameobjects.

:

The reason you are seeing it produce the same position of the GameManager is because the GameManager is at (0,0,0) and your prefabs are all (0,0,0).

:

I don’t know how you reference the towers because you never shared that part but that’s the problem.