How to make a RUNTIME BUTTON under a RUNTIME GameObject

is there a way we can make a runtime button under a runtime gameobject?i was able to do a runtime gameobject inherited with all the components/materials from UIToolkit.

heres my code:

public class loadImage : MonoBehaviour 
{
 
	public UIToolkit duplicate_kit;
	public Material material;
	public UIButton b1, b2;
	public MeshFilter meshFilter;
	public MeshRenderer meshRenderer;
	public Mesh _mesh;
	

	void initKit()
	{
	 
		Material duplicateMaterial = new Material (material.shader);
		duplicateMaterial.CopyPropertiesFromMaterial(material);
		material = duplicateMaterial;
		
		GameObject loadImageToolkit = new GameObject("duplicate_toolkit");
		loadImageToolkit.transform.parent = GameObject.Find("UI").transform;
		loadImageToolkit.layer = LayerMask.NameToLayer("UILayer");
		

	   	duplicate_kit = loadImageToolkit.AddComponent<UIToolkit>() ;
		duplicate_kit.texturePackerConfigName = "friendsImageSheet";
		duplicate_kit.material = duplicateMaterial;

		meshRenderer = loadImageToolkit.AddComponent<MeshRenderer>();
		meshRenderer.renderer.material = duplicateMaterial;

		meshFilter = loadImageToolkit.AddComponent<MeshFilter>();
   		_mesh = meshFilter.mesh;
		

	}

	void Start() 
	{
		 initKit();

//		 b1 = UIButton.create( duplicate_kit, "FriendsAvatar.png","FriendsAvatar.png",0,0);	
//    	 b1.pixelsFromTopLeft ( 60, 0 );
//	     StartCoroutine(getImage(b1));
		
		
		 b2 = UIButton.create( duplicate_kit, "FriendsAvatar.png", "FriendsAvatar.png" , 0,0 );
		 b2.pixelsFromTopLeft( 120, 0 );
		 StartCoroutine(getImage(b2));
		
		
		 b1 = UIButton.create( (UIToolkit)GameObject.Find("duplicate_toolkit").GetComponent(typeof(UIToolkit)), "FriendsAvatar.png","FriendsAvatar.png",0,0);	
		 b1.pixelsFromTopLeft ( 120, 0 );
		 StartCoroutine(getImage(b1));

	}
   
	IEnumerator getImage(UIButton uib)
    {      
		WWW imageRequest = new WWW("https://graph.facebook.com/xxxxxxxxx/picture?type=small");	
		yield return imageRequest;
		Texture tex = imageRequest.texture;
		
		uib.manager.renderer.material.mainTextureScale = new Vector2(18.0f,20.05f);
		uib.manager.renderer.material.mainTexture = tex;
    }
	
}

the main goal is the b2 button should appeared under duplicate_toolkit(Game Object)

its like :

duplicate_toolkit

UIButton

I’m not really sure if this is what you are asking, but you could create a prefab called UIButton with the appropriate OnGUI() function. You could then use the GameObjet.AddComponent() function to add that prefab to the duplicate_toolkit gameobject. Instantiating and adding as required.

I’ve never actually tried it, but theoretically that should give you the hierarchy you are looking for.

thanks for the reply brian, i was also thinking about using prefab, but unfortunately i cannot used onGUi function since im using UIToolkit for swiping container, if i used onGUI the images im downloading using www funtion will not covered the swiping effects. the image will be static, while other buttons has a swiping effects.