Case of the strangely shifting sprites solved

So it’s about here where all my sprites (or my game world) started to wander. A fairly annoying circumstance where suddenly my sprites so carefully compliant with my grid and grass background suddenly started deciding they would be somewhere else.

I took one of my existing prefabs and destroyed/recreated it. I did this one more time and I finally worked out what was wrong.

We created these empty grouping objects called Attackers and Defenders that were parents to the different sprite/animation objects. I decided I didn’t want these objects on any part of the screen so guess what I did? I shifted them both to some point of the screen (below and to the left of (0,0,0). So what happened to my transform of my child objects? Yep - they were all now transforms in relation to the parent object rather than the game canvas.

Anyway, I just thought I’d relate this here in case it helps anyone. Be careful of the transforms of parent objects.

There’s one more thing to know about relative transforms between parents and children objects, specifically how Unity “changes” those transforms when moving around objects in the Hierarchy.

Every time you put inside (or remove from) a parent another object, the transform of the newly childed object is modified in order to mantain the same transform it had before, so it remains in the same place relative to the world origin.

I.E.: Object1 in 100,0,0 - Object2 in 0,100,0
If you child Object2 under Object1, the new transform of Object2 will become -100,100,0. If you child Object1 under Object2, Object2 will have a transform of 100,-100,0.

Be aware, this is done EVEN for sizes. If you child an object inside a parent of size 1,1,1, the childed object will retain the same size it had before. But if you child an object inside a parent with size 10,10,10, the child size will be scaled by a factor of 0,1.

Privacy & Terms