Object Doesn't Move to Child's Position

I have a two prefabs (tiles) which have children (squares). I have them in a list where both tiles have a special square named “Skull”. That Skull has variable called Square, which means the child game object itself.

Right now I’m trying to move my player to each tile’s Skull Square with this piece of code:

if(Input.GetKeyDown(KeyCode.S)

{
     Vector3 pos = board[Random.Range(0, board.Count)].skull.square.transform.position;
     player.transform.position = pos;
}

For the other tile this works well:
6078891--659562--upload_2020-7-11_14-13-17.png
6078891--659565--upload_2020-7-11_14-13-37.png
But on the other tile the player moves to a wrong position:
6078891--659568--upload_2020-7-11_14-14-17.png
6078891--659571--upload_2020-7-11_14-14-33.png

I’ve checked that the Skull square has the correct game object attached to it, and the square is positioned correctly on it’s parent.

I suspected that this had something to do with the square being a child object. I’m aware that the inspector shows the child’s position relative to parent, and that transform.position is supposed to give out the global position. When I Debug.Log the pos -variable, it doesn’t give out the same position as in inspector, so therefore transform.position is returning the global position. Also the player’s position is the same as pos. It just doesn’t show up in the correct position visually.

I don’t really understand why the code works for the first tile but not the second one, so if you know where the problem is, feel free to tell me.

What you’re doing seems very reasonable and using Debug.Log() is definitely a great way to get intel.

I’m sure you’re also aware that what you are calling a “Skull square” does not look like where the skull is… it looks like debris to me, especially as I can see a skull nearby.

Note that the inspector position is always the local position relative to parent, which is only equal to global at the top level of the hierarchy.

Some other things to look at: is something else also moving the player, such as an animation or player movement script.

Another possibility is that the visible part of the player isn’t where the transform that you are setting, and that can also apply to the skull, like an offset in the prefab hierarchy. This is a fairly easy thing to knock out of alignment when editing prefabs.