Flattening and encoding an octree in unreal

This is an octree for a voxel engine I am creating, I have been having a dilemma with choosing a way of flattening and/or encoding this octree, so I have a way of sending data over to a client.

struct OctreeNode {
BYTE value;
bool is_leaf = true;
OctreeNode* children[8];
OctreeNode* parent;
};

I have considered translating it into a long string, but I have fears that it will have performance issues with more defined octrees

I’m by no means an expert, but how about giving each node an ID? Then you can send the value, parent ID, and the ID’s of any children easily. You might need another byte for the number of children as well, but if the ID is an integer a node is just an array of bytes/integers.

Depending on how much control you have over the sending, you could also potentially apply some compression algorithm on the data if you have a lot of nodes that you are sending.

I was able to (somehow) complete the replication by flattening the octree with a Tmap<Octree struct, Int32> and mapping the structs then using FBase64 to encode the map to a FString so I could send it over to the client where I used a unwrap function to unwrap it on the client.

If anyone is having the same issues as me, I would be glad to do a code drop.

1 Like