In the default GameViewController template, the GameViewController has a section in the viewDidLoad function that copies objects and graphic scene editors.
class GameViewController: UIViewController { private var sceneNode: GameScene! override func viewDidLoad() { super.viewDidLoad()
These Entities and Graphs array variables are declared in GameScene. Then retrieve the graph from the array.
class GameScene : SKScene { var entities = [GKEntity]() var graphs = [String : GKGraph]() var navigationGraph: GKGraph<GKGraphNode>! override func didMove(to view: SKView) { self.navigationGraph = self.graphs.values.first // <-- get a reference to your graph } }
If the SpriteKit editor has more than one graph, use the query to retrieve it by name.
self.navigationGraph = self.graphs.values.first(where: {$0.name == "GraphName"})
source share