0

I'm learning sample code SceneKit team demonstrated in SceneKit: What's New. I find a file has extension .gks and it seems is resource of GameplayKit.

Here is it loading:

#if EnableGamePlayKit

    _gkScene = [GKScene sceneWithFileNamed:@"Art.scnassets/scene.gks" rootNode:_scene];

#endif

What's the .gks file? I keep looking for a long time but failed. How to create and use it?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
ooOlly
  • 1,997
  • 21
  • 31

2 Answers2

1

A .gks file is created by archiving a GKScene instance using NSKeyedArchiver. You can learn more about GameplayKit on the Apple developer website.

mnuages
  • 13,049
  • 2
  • 23
  • 40
  • I haven't find the archiving code in this demo as well as other resource. About +sceneWithFileNamed, Apple doc say : Loads the specified SpriteKit scene file, creating a GKScene object containing the SpriteKit scene and associated GameplayKit objects – ooOlly Jul 06 '17 at 09:59
0

There is zero documentation on this that I can find, it took me hours to get this to properly work. The gks file is automatically generated when you add components to your scene via the SceneKit builder. it will automatically create GKEntity and GKSCNNodeComponent instances for nodes that have components attached to them, so that you can use them without ever having to create them via code.

Note, this method is horrendously bugged. After you create the GKScene, you need to go through the entities and remap the components to the entity it is given, because the entity variable in the component stays as nil. You also need to re-add a copy of the component back into the entity, because when you try to find the component with OfType, it will not recognize the type, even though you can print the contents of the entity and clearly see that everything is declared the same type. I will update this answer later on for people so that they can see code as to how to get this to work properly.

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44
  • What have you found during 1.5 years since you said about gks file and GKScene. Could you be more specific about the automation process? How could you add components (GKComponent) to the scene editor? I could not figure out yet. Thanks in advance. – Sungwook Kim Jun 03 '19 at 16:51
  • Thanks I found the answer by myself. The funny thing is that when you understand all things going on under the hood, all the document released by Apple Inc. sounds obvious and clear. Apple should provide more explanation for the newcomers. – Sungwook Kim Sep 27 '19 at 05:15