Animations and SCNTransactions sometimes delay while using multiple SCNRenderers

I'm using 3 SCNRenderers to render the same game scene from 3 different perspectives. It's a third person shooting game. A day before, I found that when all the renderers were working, the main hero's walking animation disappeared, but I could still control him to move. Then I found this: https://forums.developer.apple.com/thread/66890. By setting the render function's atTime with CFAbsoluteTimeGetCurrent(), the animation did appear. However, when the hero was running 2 animations, for example, firing while walking, the rendered result only showed 1 of them.


I did solved the problem by saving the time which was given by the SCNView's render function, and then applied it to each renderer's render function. Here is my solution sample:


var globeTime:TimeInterval = 0

//the SCNView's render function:
func renderer(_ aRenderer: SCNSceneRenderer, 
              updateAtTime time: TimeInterval) { 
     globeTime = time
     //...
}

//each renderer's render function:
renderer.render(atTime: globeTime, 
                viewport: viewport, 
                commandBuffer: commandBuffer, 
                passDescriptor: renderPassDescriptor)


I successfully make those renderers render the right thing. However, weird things start to happen. Sometimes, when it's time for an animation or a SCNTransaction to begin, nothing happens. All the animations and SCNTransactions just pause in their initial state. But the game is still running, which means I can still control my hero to move and jump without any animations. After a few seconds, the paused animations and SCNTransactions start.


I have no idea what causes this. I've checked those model's isPaused property as well as the SCNView and the SCNRenderer's isPlaying and loops property. Still, I cannot figure out why. Can anyone help me? Thanks.

Accepted Reply

It seems that I've got the answer. Before I created an optimisation that stops the renderers from rendering when I don't need them. However, it seems that when a renderer works, the game runs faster. So I guess by turning on and off those renderers, the time of the scene becomes unstable, which could affect the animations' timeline.


Anyway, making those renders work all the time solves the problem.

Replies

It seems that I've got the answer. Before I created an optimisation that stops the renderers from rendering when I don't need them. However, it seems that when a renderer works, the game runs faster. So I guess by turning on and off those renderers, the time of the scene becomes unstable, which could affect the animations' timeline.


Anyway, making those renders work all the time solves the problem.