Dragging child item in Horizontal Layout Group


I have a panel with a Horizontal Layout Group applied to it. I have 4 objects in the panel and they all space out nicely.

One of the items has a script on it that allows the user to drag the sprite around, this works fine with the Horizontal Layout Group turned off, but with it turned on it locks the sprite into place and I cannot drag it anymore.

Is there a way to be able to move the sprite around whilst in a panel with Horizontal Layout Group applied?

*note - if the sprite is dropped somewhere other than some predefined spots it snaps back to its original position.


You’ve probably figured this out since 2020 but in case anyone else needs it-

Add a Layout Element to each of the children in your Horizontal Layout Group. When you begin dragging the object, set Ignore Layout to true on that element. The Layout Group will no longer affect its position and you can drag or animate it as you wish. When you drop the object outside the predefined spots, turn Ignore Layout back off and it’ll snap back into place where it used to be in the original set.