You can use wp_list_pages()
instead. Just pass your post type in if you’re trying to list something other than Page-pages:
<ul>
<?php wp_list_pages(array(
'post_type' => 'yourposttype',
'title_li' => ''
) ); ?>
</ul>
If you wanted to display this on all post types you could use
<ul>
<?php wp_list_pages(array(
'post_type' => $post->post_type,
'title_li' => ''
) ); ?>
</ul>
which would automatically grab the post type of the currently viewed item and display the full tree for that post type.