Posts

Post not yet marked as solved
1 Replies
0 Views
For anyone who might have any thoughts, here is a page that shows how to create a subclass of GKGridGraphNode and construct a GKGridGraph using your custom node: github.com/thesecretlab/iOSGameDevCookbook3rdEd/blob/master/01-layingout.playground/Pages/Graphs.xcplaygroundpage/Contents.swift That is from the book iOS Game Development Cookbook, and it was the only actual code example I was able to find on the internet showing how to subclass GKGridGraphNode for usage in a GKGridGraph. Theoretically that technique sounds fine: create a GKGridGraph using the main constructor, then remove nodes in the grid and replace with your custom nodes using connectToAdjacentNodes. The problem is that GKGraph.remove() method takes around 1,000x times longer to remove a node than it does to add a node. I don't know why. I wanted to create an on-the-fly ephemeral grid graph for each agent that needs pathfinding per turn in my game, and use the graph to find an optimal path using GKGraph.findPath() then just throw away the graph once the path was found, then rinse and repeat. That idea will not be possible due to the performance of the remove() method as it takes way too long to create the grid graph. If anyone has any ideas, please let me know. I am stumped and pretty much totally roadblocked at this point from using GameplayKit, as usage of the grid graph is a fundamental part of my game engine.