You gave it a world position. You meant a local one.

The problem
An offset used as a world position.
var hat = HatPrefab.Clone();hat.SetParent( Head, false ); hat.WorldPosition = new Vector3( 0, 0, 8 );
WorldPosition is measured from the middle of the map. ( 0, 0, 8 ) is just above it.
The fix
Measure from the parent.
LocalPosition is measured from the parent. ( 0, 0, 8 ) means 8 above the head, wherever the head is.
WorldPosition→from the map
LocalPosition→from the parent
The fix in code
Offsets are local.
var hat = HatPrefab.Clone();hat.SetParent( Head, false ); hat.LocalPosition = new Vector3( 0, 0, 8 );
Move the player, turn the head, and the hat stays put on it.
Watch out
SetParent's second argument.
It decides whether the object stays where it is, or keeps its local numbers.
- SetParent( p, true )
- stays where it is
- SetParent( p, false )
- keeps its local numbers
- Attaching
- false, then set local
The rule
Offsets from a parent are local.
- In the world
- WorldPosition
- From the parent
- LocalPosition
- Attaching
- SetParent( p, false )