I have an octree that I want to use to perform pathfinding in 3D space. I'm using Morton codes to order the nodes with the intention of being able to easily find the nodes nearby any given node. It appears to work great; any subset of the nodes I grab are clustered relatively close together. Where I'm struggling is finding an efficient way of getting a node's direct neighbors.
An earlier version of the tree had it subdivide the tree until the leaves were all equal sized nodes at the size I wanted. This made it easy to find neighbors as there was a consistent offset between each node, so I could just recalculate the Morton code at the position I expected to find a node, and then retrieve the node based on the code. But I'm trying to be more efficient with the tree by not breaking it down as much in areas where there isn't as much geometry (e.g. where I would get 8 empty children). As a result, I no longer know how many neighbors a given node may have, nor the size of any of the neighbors (other than it being a power of 2).
My initial thought was to search nearby nodes in either direction in the array, which would work, but I'd have to cast too wide a net to be guaranteed to get all neighbors, and I'd have spent time evaluating a ton of nodes that I don't need. A quick test indicates that not even 50 nodes in either direction in the array is guaranteed to get me all neighbors.
The tree is static, so I could perhaps do a one time generation of a node's neighbors using the above brute force method and store the neighbors; but I fear this may increase the initial loading time of the program beyond acceptable levels. Is there an algorithm that can find the neighbors in real-time?
Edit: Reworded the question to clarify what I'm looking for and what I've tried.