moving child objects in hierarchy and keep stacks/sorting? Help needed

Hello, so I really need help with this one. How I move all child objects from “fem1” to “character” and keep stacks/sorting…

my script does it like this(3rd pic) and 2 pic is how it should be… :frowning:

script:

#pragma strict
//This script must be attached to clothing or body and functions can be used by UI buttons

var selected : boolean;
private var newParent : GameObject;
private var parentOBJ : Transform;


function Start () {

newParent = GameObject.Find("character");
parentOBJ = transform.parent;


}

function Update () {

var renderers = GetComponentsInChildren(Renderer);
var transforms = GetComponentsInChildren(Transform);

    if (selected)
        {

            gameObject.tag = "active";

                       
            for (var r : Renderer in renderers) { r.enabled = true; }

            for (var child : Transform in transforms) { child.transform.parent = newParent.transform;    }
        }
    else
        {

            gameObject.tag = "de_active";

            for (var r : Renderer in renderers) { r.enabled = false; }
            this.transform.parent = parentOBJ.transform;   
           

        }


}

function MAKE_OBJ_ACTIVE ()
{
     selected = !selected;
}

You need to only change the top level gameobject’s parents. You can get only the top level objects by using the transform in a using statement (which is not very intuitive to me)

Like this: for(var child : Transform in parentOBJ.transform)

Thank you for reply :slight_smile: I tested that script it moved parent object including all childrens. I mean I want to keep parent object, but exctract all children objects to object in hierarchy. Problem is if move whole package like this to newparent “character” pre-setup animations won’t work I think bone data and everything must be in root and in order. I’am very bad in explaining hope it makes sense.

I think this is one way to do it :smile: it’s pretty complex system… but it works. Critics?

explained somehow in picture - https://gyazo.com/bde7b709aaae7da0b00f9d1dc8ac20c7

#pragma strict

var item : boolean;
var character : boolean;
var characterExtracter : boolean;

var selected : boolean;

private var newParent : GameObject;    private var newParent2 : GameObject;
private var parentOBJ : Transform;


function Start ()
{

newParent = GameObject.Find("character");    newParent2 = GameObject.Find("CHARACTER_EXTRACTER");
parentOBJ = transform.parent;


}

function Update () {

var renderers = GetComponentsInChildren(Renderer);
var transforms = GetComponentsInChildren(Transform);
var allChilds;

    if (selected)
        {
            gameObject.tag = "active";       
            for (var r : Renderer in renderers) { r.enabled = true; }
           
            if (item)
            {
            this.transform.parent = newParent.transform;   
                //for (var child : Transform in transforms) { child.transform.parent = newParent.transform;    }
            }


            if (character)
            {
                this.transform.parent = newParent2.transform;   
            }


            if (characterExtracter)
            {
                allChilds = transform.GetChild(0);
                for (var child : Transform in allChilds) { child.gameObject.transform.parent = newParent.transform;    }
            }
           

        }
    else
        {
            gameObject.tag = "de_active";
            for (var r : Renderer in renderers) { r.enabled = false; }
               
           
            if (item)
            {
            this.transform.parent = parentOBJ.transform;   
            }
        }


}

function MAKE_OBJ_ACTIVE ()
{
     selected = !selected;
}