I have the bare bones of an AUv3 plug in. I have used UIHostingController to allow me to add a SwiftUI view. Then from the SwiftUI I have added a SprikeKit scene which I want to use to start building an interface for the AU.
It's a very basic GameScene for now. If I run one instance of it in Logic then it's OK. If I add another instance it crashes with a Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) error.
This seems to be down to how I declare a SpriteNode variable. If I declare it within the GameScene as a "let" then it's fine. If I declare it outside the class - (see hashed code) then it will crash with two instances. It would be useful to me later on for this to be a public variable as I want to perform functions on it outside of the class.
Is there a better way to declare the SpriteNode variable to make it stable?
import SpriteKit
//public var ball = SKShapeNode(circleOfRadius: 30)
var ball = SKShapeNode(circleOfRadius: 30)
class GameScene: SKScene {
let ball = SKShapeNode(circleOfRadius: 30)
override func didMove(to view: SKView) {
//physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
ball.position = CGPoint(x: 200, y: 200)
ball.fillColor = .lightGray
self.addChild(ball)
}