Search code examples
swiftsprite-kittvosapple-tv

What is the correct UIFocusItemContainer for a SKScene? (tvOS 16)


I implemented a game for Apple TV where I have multiple SKSpriteNodes in a SKScene. Before tvOS 16 everything worked correctly, I could move around with the remote and focus all items in the correct way. Now, with tvOS 16, the app crashes with the following error:

Focus item RandomSKSpriteNode has a parent focus environment of MySKScene but this environment does not provide a container for focus items.

So then I tried to just set the SKScene's view, the parent environments focus item container, an empty view and more as the SKScene's focusItemContainer - this fixed the crash, but the focus behaves quite randomly. Some of the nodes cannot be focused then anymore, and the focus just jumps to randoms nodes, and not the one in which direction I swiped to.

override var focusItemContainer: UIFocusItemContainer? {
    return view // parentFocusEnvironment?.focusItemContainer // UIView()
}

Does anyone have an idea what I have to set here as the focusItemContainer? It's so strange because everything worked before and I also cannot find anything about any breaking changes in the release notes. If you have any hints for that issue please let me know!


Solution

  • I just tested the issue again with an tvOS 16.4 simulator and it seems like the bug is fixed as everything works as before without any focusItemContainer!