SetParent changing the relative position of the parent
I feel like this is a bug.
Basically I have two game objects, one at position -7,0,0 and one at 7,0,0
http://i.imgur.com/A3ENwad.png
http://i.imgur.com/UcSeP21.png
These two have a script on them that creates a Tile class script, which in turn creates a GameObject and sets the parent to the first object.
http://i.imgur.com/NBTYa6P.png
(tiles is an array of Tile, but when testing t was 0 and not in any kind of loop. SetSprite alone causes no issues. It is only when SetParent is called. SetParent is the last thing called.)
When the parent is set, the parent objects are moved on screen to the centre, but retain their positions. This means they are still -7,0,0 and 7,0,0 but they occupy the same space on screen.
http://i.imgur.com/ZicSnJ1.png
They have no parents of their own, they are just at different positions while in the same position. I have to move them to -14,0,0 and 14,0,0 to get them back to where they should be. Their positions are completely independent of other objects in the game and I can't see why.
Your script sets the object as parent of itself, are you sure about that?
@Epifouloux Can you explain? I don't think I do. tiles[t] is an instance of Tile. tiles[t] is in a separate class to the Tile class. It calls SetParent as a function of Tile which then sets the parent on m_sprite, m_sprite is the only object having it's parent set.
It's more common to include the important lines of the script as text, inside your question. Often when you test, you simplify to something small that causes the problem, so you can post just that.
Having code in a picture, or as a link, makes it harder for people to read/test what you have. Also, I moved this to the HelpRoom (since it seems like an individual problem, not completely understanding a part of parent/child, or perhaps a bug.)
Answer by Fikule · Jun 18, 2016 at 02:28 PM
"Solved" it.
It was simply basing the position of the movement indicator on the child object's position (0). Not sure why though, but it's working at least.
I assume the movement indicator places itself at the average position of all the component (child) pieces?