0 Replies
      Latest reply on Jul 12, 2019 6:43 AM by jjacob
      jjacob Level 1 Level 1 (0 points)

        I'm not able to load GameplayKit entities from the scene with GKComponents working. In Xcode 10.2.1 I started with a new Spritekit/GameplayKit project. I added a new component class to the project:

         

        class TestComponent : GKAgent2D {
        
            override init() {
                super.init()
                
                let goal = GKGoal(toWander: 1)
                behavior = GKBehavior(goal: goal, weight: 1)
                
                print("Wander goal added")
            }
            
            required init?(coder aDecoder: NSCoder) {
                super.init(coder: aDecoder)
            }
            
            override func didAddToEntity() {
                super.didAddToEntity()
                
                if let entity = self.entity, let nodeComp = entity.component(ofType: GKSKNodeComponent.self) {
                    self.delegate = nodeComp
                    print("Added node component as delegate")
                }
            }
            
            override func update(deltaTime seconds: TimeInterval) {
                super.update(deltaTime: seconds)
                print("\(self.position) @ \(self.velocity)")
            }
        }
        

         

        I then set the "Hello World" string to have this component. When I run, the "Hello World" sprite isn't seen and the logs show:

         

        Wander goal added
        Added node component as delegate
        SIMD2<Float>(0.0, 0.0) @ SIMD2<Float>(0.0, 0.0)
        SIMD2<Float>(-nan, -nan) @ SIMD2<Float>(-nan, -nan)
        SIMD2<Float>(-nan, -nan) @ SIMD2<Float>(-nan, -nan)
        SIMD2<Float>(-nan, -nan) @ SIMD2<Float>(-nan, -nan)
        SIMD2<Float>(-nan, -nan) @ SIMD2<Float>(-nan, -nan)
        ...
        

         

        Is there something simple I'm missing here or is there are bug with GKComponents set in the scene file?

         

        - jjacob