New UI and reusing a hierarchy of UI gameobject.


With the new UI, what is the recommended way to reuse a hierarchy of UI gameobject multiple times ?

Take the following image for example:

Let’s assume I designed one of those elements with the new UI. I would have in my scene something like that :

It doesn’t seem possible to create nested prefabs (without paying for an extention).
So what would be the way to reuse this set of gameobject, and make sure that if I modify one of them, they will all get updated ?

I have 2 type of usages:

  • Each element is instanciated dynamicaly at runtime.
  • Each element is instanciated in the editor, and can be arranged in a layout.


I instantiate menus in a scroll panel that uses a vertical layout group:

public GameObject itemPrefab;
public RectTransform ParentPanel;

GameObject newItem = Instantiate(itemPrefab) as GameObject; 
newItem.GetComponent<MenuItm>().myArrayNumber = myCount;
newItem.transform.SetParent(ParentPanel, false);
newItem.transform.localScale = new Vector3(1,1,1);

I have a script on the panel (itemPrefab) that’s called MenuItm and has a public int to store the number so I can know which panel is which.

You can also have complex objects with numerous child objects that you can reference like this:

spellImage = newItem.gameObject.transform.GetChild(0).GetComponent<Image>();

GetChild(0).GetComponent(); is just an image with, in my case, an image of a spell on it.