Question about getParent() and getAncestor()

I’m still relatively new to panda3d, and I’m currently working on a collision event handler for when players collide with the ground in a way that they can be considered “standing”. To do this, I need the node two levels up from the from object; the parent of the parent of the from object.
Since this function is going to be called very often, Is it better to just use getParent() twice? Or would getAncestor(2) be better? I’m not quite sure as the API reference states that getAncestor requires iterating through the path.

np.getAncestor(2) is more or less the same as calling np.parent.parent. I do not expect them to be significantly different in terms of performance.

It does iterate, but it iterates backwards from the node itself towards the root, kind of like this (except in C++):

np = self
while index > 0:
    np = np.parent
    index -= 1
1 Like