Tree Nodes help

Hello I have a bunch of 3d meshes in my scene. I would like to make something like Unity’s hierarchy view where you can view objects and their children. I would also like drag and drop functionality where you can drag a top level mesh onto another top level mesh and make a parent child relationship. Looking through the examples, I think this is possible but I’m having trouble implementing it. When exactly do I call treepush and treepop? Could someone provide a source code example? :smiley:

I have some code here. IT keeps saying that basically I’m calling pop too much. Its failing an assert. What should I do?

My recursive function

void treeChildren(ImGuiTreeNodeFlags node_flags, bool isOpen, int index)
{
if (isOpen)
{
for (int p = 0; p < meshList[index].children.size(); p++)
{
bool o = ImGui::TreeNodeEx((void*)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str());
treeChildren(node_flags, o, p);
ImGui::TreePop();
}

}

}

Code here

//game object window
if (showGameObjects)
{
if (ImGui::Begin(“Game Ojects”, &showGameObjects, ImGuiWindowFlags_AlwaysAutoResize))
{
ImVec2 size = ImVec2(200.0f, 130.0f);
ImVec2 sizeBtn = ImVec2(75.0f, 25.0f);
static char buf[128] = “”;
//show a list of game objects
ImGui::LabelText("", “Game Objects in Scene.”);

			if (ImGui::TreeNode("Object List"))
			{
				ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize() * 3);
				for (int i = 0; i < meshList.size(); i++)
				{
					ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
					bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, meshList[i].name.c_str());

					treeChildren(node_flags, node_open, i);

					/*if (node_open)
					{
						ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "child two");
						ImGui::TreePop();
					}*/
				}
				ImGui::PopStyleVar();
			}

			ImGui::TreePop();
		}
		ImGui::End();
	}

Nevermind I got it working.

void treeChildren(ImGuiTreeNodeFlags node_flags, bool isOpen, int index)
{
if (isOpen)
{
for (int p = 0; p < meshList[index].children.size(); p++)
{
if (meshList[index].children[p].children.empty())
{
node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet
ImGui::TreeNodeEx((void*)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str());
}
else
{
bool o = ImGui::TreeNodeEx((void*)(intptr_t)p, node_flags, meshList[index].children[p].name.c_str());
ImGui::TreePop();
treeChildren(node_flags, o, p);
}
}
ImGui::TreePop();
}
}


	//game object window
	if (showGameObjects)
	{
		if (ImGui::Begin("Game Ojects", &showGameObjects, ImGuiWindowFlags_AlwaysAutoResize))
		{
			//show a list of game objects
			ImGui::LabelText("", "Game Objects in Scene.");

			if (ImGui::TreeNode("Object List"))
			{
				ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, ImGui::GetFontSize() * 3);
				for (int i = 0; i < meshList.size(); i++)
				{
					ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
					bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, meshList[i].name.c_str());

					treeChildren(node_flags, node_open, i);

					/*if (node_open)
					{
						ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "child two");
						ImGui::TreePop();
					}*/
				}
				ImGui::TreePop();
				ImGui::PopStyleVar();
			}
		}
		ImGui::End();
	}