How to move a gameObject without affecting its childrens' positions?

Hello, I’m working on a File manager-like structure with NGUI, so far so good.
The way I got my “Folder” set up, is that a folder consists of “Parts” which consists of a Background, Icon and a Label, “Contents” which carry the folder’s content, a “FolderContent” could either be a “Folder” or “FILE”.

Whenever I “Open” a folder, (in short) I hide the previous folder contents and show the new ones’.

The problem is, when I pickup a folder and move it with the mouse (drag and drop or just pick and hold) I auto-organize the current folder’s contents (reposition them), when a folder gets repositioned (n shifts to the left/up), its contents also shift with it, so when I open the folder later, I will see that the contents’ are not positioned correctly.

I can get around that by using one of my methods “OrganizeContents” which does exactly what you think, but that wouldn’t be necessary to do each time I open a folder, it’s redundant.

Have a look:

Any ideas how to move a gameObject without affecting its children?

Another work-around would be to move the Folder’s “Parts” when auto-positioning it, but that would bring inconsistencies in other places.

If I can’t do what I’m asking for, any other work-arounds beside the two I mentioned?


What is the reason behind storing subfolders and files as children of the folder? I know nothing about NGUI, but if I were to code it in pure Unity, I would probably store subfolders and files as an arrays of GameObjects in parent folder script, not as standard GameObject children. If required, I would add another property for keeping reference to parent (null for top level folder):

public GameObject[] folders;
public GameObject[] files;

public GameObject parentFolder;

This way, repositioning parent would not affect children position. You can of course change GameObject in above snippet with proper objects.

EDIT: converted to answer after exchanging a few comments with OP (under question).

The best method for moving the parent object without moving the child objects would be to save the child object’s absolute position (transform.position) prior to moving the parent, then, after calling the move on the parent, set the child’s absolute position back to what it was before the move.