getChildren not available when creating a page

Hi, I have a panel created using Panels Application. My goal is to have the panel display the navigation for one of the page templates. The problem is that the macro responsible for this doesn’t work the first time, it seems that the childrens are not available when creating a page from the template. Only by changing the name of the page does everything work fine.

Some pseudocode because i have to hide some parts of code:

{{velocity}}

#set($parent = $doc.getParent())
#set($title = $doc.getTitle())
#set($list = $doc.getChildren())

 #set($items =[])
 3set($tmp = $items.add( { "value" : $list[0] } ) )
 #set($tmp = $items.add( { "value" : $list[1] } ) )


(((
#foreach ($tab in $items)
  #set($tabdoc = $xwiki.getDocument($tab))
    
        {{menu type="vertical"}}
        * [[$tabdoc.getTitle()>>$tab]]
        {{/menu}}
  
#end

)))

{{/velocity}}

https://extensions.xwiki.org/xwiki/bin/view/Extension/Children%20Macro/

This macro works normally and already when creating a page it shows a tree with its children. Is it possible in velocity script to access data from this macro to process it further?