GameplayKit Spatial Partitioning: GKRTree

I have been playing around with the GKRTree but I am unable to make it work properly. It would be great the have a working example of adding, removing and searching elements


https://developer.apple.com/reference/gameplaykit/gkrtree


I am bit unlear on how exactly the boundingRectMin and boundingRectMax should be created when adding an element, and when searching for them.

My idea is to add all enemies in the tree and using the position of my main character, find which enemies are around me.

Replies

I'm on the same page. I've created a playground example https://github.com/bamse16/swift-rtree

I sent a request to the Apple Developer Technical Support, because Quadtrees do not work either. Feedback below (they did reference your example):



A similar reported issue regarding GKRTree has an attempted fix in iOS 11. It’s the same problem as demonstrated in iOS 10 (and macOS 10.12) by the playground here: https://github.com/bamse16/swift-rtree


Are you in a position to install the beta and check out both of these issues there? Unfortunately, there is no known workaround for the referenced GKRTree bug in iOS 10.