In SceneKit SCNAction hangs when called from completion handler of RunAction

后端 未结 2 1448
旧时难觅i
旧时难觅i 2021-01-27 11:04

Calling an SCNAction from the completion handler of RunAction seems to hang SceneKit.

A touch event or rotating the device seems to unblock the hang.

To reproduc

相关标签:
2条回答
  • 2021-01-27 11:39

    This happens because by default SceneKit is not rendering continuously. When tapping the screen the scene is changed and a new frame will be rendered. That's why the moveBy action is not triggered immediately after the rotateBy action.

    Try setting SCNView's renderContinuously property to true like so:

    scnView.rendersContinuously = true
    ship.runAction(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 3.0)) {
        print("DONE ROTATE")
        ship.runAction(SCNAction.moveBy(x: 1, y: 0, z: 0, duration: 3.0), completionHandler: {
            print("DONE MOVEBY")
            scnView.rendersContinuously = false
        })
    }
    
    0 讨论(0)
  • 2021-01-27 11:53

    Using SCNTransaction with a completionBlock does not suffer from the same problem, so this works fine:

            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 3.0f;
            SCNTransaction.SetCompletionBlock(() =>
            {
                Console.WriteLine("DONE ROTATE");
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 3.0f;
                SCNTransaction.SetCompletionBlock(() =>
                {
                    Console.WriteLine("DONE MOVEBY");
                });
                ship.Position = new SCNVector3(1.0f, 0.0f, 0.0f);
                SCNTransaction.Commit();
            });
            ship.EulerAngles = new SCNVector3(0.0f, (float)Math.PI / 2, 0.0f);
            SCNTransaction.Commit();
    

    (Also using CABasicAnimation with CAAnimationDelegate to do the callback works OK.)

    Since SCNTransaction and CABasicAnimation work, but RunAction doesn't, it really looks like an Apple bug in RunAction.

    0 讨论(0)
提交回复
热议问题