Setting hierarchy order of UI objects by script

Hello everyone !

Then I am blocked ! I shall wish that my GameObject changes place in the hierarchy with a script, in which I could execute later. (Here is a photo opposite to see the trajectory of the button in the hierarchy) :roll_eyes:

I wish that the button changes place in the hierarchy and which goes to “Destination”, all this to a script which I could execute later with a trigger or a button.

Here we are, if you find solution to my problem, I owe you the respected! :slight_smile:

Changing place and changing parent are two different things. Both are straight forward though.

9 Likes

The problem it is how we make? That’s what I look :frowning:

Make what? All those links contain example code.

I want to move an object cloned in the hirerchy, for me it is impossible even with the links as you crossed me

Hey there. It’s a little weird that you have a button outside of the canvas to begin with.
He did show you some relevant links/docs about the issue.
If you can explain why the button is outside in the first place, maybe we can offer an alternative solution.

If you do not understand how the links provided relate to your issue, you might want to consider taking a step back and going through some of the introduction material, as well as some tutorials (here on the Unity website). It will slow down your personal game making, at first, but the knowledge you’ll learn and be able to use going forward will be well worth it. :slight_smile:

Hi, then thank you KelsoMRK for the links, in the end I managed and I succeeded.
And you, methos5k, I have the impression that you are everywhere :p.
Anyway, I thank you to you and I made a success, I send you the script, I crossed 3 hours to find a solution and I arrived at that.

Says it I if he simpler there.
```csharp
**[/B]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; //Required when using UI Elements.
using UnityEngine.EventSystems; // Required when using event data.

public class Active_cardV2 : MonoBehaviour
{
//ASSIGNATIONS DES CARTES

public GameObject Carte1_des;
public GameObject Carte2_des;
public GameObject Carte3_des;
public GameObject Carte4_des;

public GameObject carte1;
public GameObject carte2;
public GameObject carte3;
public GameObject carte4;

//DEPLACEMENT DES CLONES (Fix)

void Start()
{
    Carte1_des = GameObject.FindWithTag("Carte1");
    Carte2_des = GameObject.FindWithTag("Carte2");
    Carte3_des = GameObject.FindWithTag("Carte3");
    Carte4_des = GameObject.FindWithTag("Carte4");
    Destroy(Carte1_des);
    Destroy(Carte2_des);
    Destroy(Carte3_des);
    Destroy(Carte4_des);
}

public void Maj_1()
{
    carte1 = GameObject.FindWithTag("Carte1");
    carte2 = GameObject.FindWithTag("Carte2");
    carte3 = GameObject.FindWithTag("Carte3");
    carte4 = GameObject.FindWithTag("Carte4");
}

public void Maj_2()
{
    carte1.SetActive(false);
    carte2.SetActive(false);
    carte3.SetActive(false);
    carte4.SetActive(false);
}

public void carte1MOVE(Transform Joueur1)
{
    carte1.transform.SetParent(Joueur1);

    carte1.transform.SetParent(Joueur1, false);
}

public void carte2MOVE(Transform Joueur2)
{
    carte2.transform.SetParent(Joueur2);

    carte2.transform.SetParent(Joueur2, false);
}

public void carte3MOVE(Transform Joueur3)
{
    carte3.transform.SetParent(Joueur3);

    carte3.transform.SetParent(Joueur3, false);
}

public void carte4MOVE(Transform Joueur4)
{
    carte4.transform.SetParent(Joueur4);

    carte4.transform.SetParent(Joueur4, false);
}

//ACTIVER ET DESACTIVER

public void carte1true()
{
    carte1.gameObject.SetActive(true);
}

public void carte1false()
{
    carte1.gameObject.SetActive(false);
}

public void carte2true()
{
    carte1.gameObject.SetActive(true);
}

public void carte2false()
{
    carte1.gameObject.SetActive(false);
}

public void carte3true()
{
    carte1.gameObject.SetActive(true);
}

public void carte3false()
{
    carte1.gameObject.SetActive(false);
}

public void carte4true()
{
    carte1.gameObject.SetActive(true);
}

public void carte4false()
{
    carte1.gameObject.SetActive(false);
}

}
[B]**
```

Okay, well I’m glad that you got it working. For the pieces of code where you set the parent twice, - you don’t need to do that. There are 2 overloads to SetParent, so you only need to pick the one that you want :slight_smile:
Besides that, if it’s working for you, that’s good.