Local Position not changing after parenting

Ok guys so its doing what i want which is going where the parent is but i dont want it to stay in the center of the parent i want it to switch position so it will be a little on the side
( gameObject is the parent )

GameObject Islands = (GameObject)Instantiate (floatingIslands, transform.position,Quaternion.identity);
Islands.transform.parent = gameObject.transform;

Islands.transform.localPosition = new Vector2 ( -1000, 0);

but changing the localPosition isnt doing a thing

ok so i couldnt change the localposition via the parent it had to be on its own script on the child gameobject!

It doesn’t matter where the script is located; it only matters whether you’re changing what you think you’re changing (and when). You shouldn’t need to make another script just for this.

You could just instantiate the Islands where you want them (e.g. transform.position + -1000*Vector.right), rather than changing the position after the fact.

Also, assigning to transform.parent is deprecated; you should be calling SetParent instead, which lets you specify whether you want to keep the object in its current world position, or instead keep its local position intact (possibly shifting its position in the world).

2 Likes