What is the correct way to get parent / supper tree item in outliner

What is the correct way to get parent item in outliner view. I can get parent item but in some cases it not works or get unexpected results.

e.g. this is the outlier view (First Image):

As in the image given the selected item is Collection. When, I get parent of the item, I get Scene Collection which is correct.

In this way, If i want to get parent of Cube, I get Collection, which is correct. But when i get the parent of following item (View Layer), I get wrong result (Second Image).

In this case the parent returned is Scene. But I think View Layers must be the parent of View Layer. How i get first parent (first upper tree element).


I am using this code in C:

TreeElement get_parent_item(TreeElement *te_temp) {
	if (te_temp->parent) {
		te_temp = te_temp->parent;


	return *te_temp;

Any confusion, comments me… Please helps me.

It sounds like a simple bug.
This should fix it: https://developer.blender.org/P956

1 Like

Thanks! I have solved my problem. Actually the parent for View Layer to View Layers is not assigned. I assigned parent using tenlay->parent = ten; which solved my problem.