I expose an object-oriented wrapper in Swift that matches the underlying object model of Godot, this is basically a 1:1 mapping to what they have to offer.
They have an entire hierarchy of objects, starting with Object, and while some of the classes are thread-safe and can be called from any thread, others are not.
For example these chains of classes are thread safe:
The 6.0 toolchain from a day or two ago is crashing for me for an issue unrelated to this, so I will keep my eye on the fresh builds, hoping this gets fixed.
In the meantime, I came up with an ugly hack, and I am wondering if this is a terrible idea, or if we think this is an acceptable workaround:
@MainActor
class Base {
// This allows me to construct this from any actors:
nonisolated init () { }
nonisolated func demo () {
// No MainActor affinity
}
}
@MainActor
class Derived: Base {
public override init () {
// Instances of derived run on MainActor
}
func regular () {
// This method only runs in MainActor
}
}
Task {
let a = Base () // This works, no await necessary
let b = await Derived () // Need to use await here due to @MainActor
}
This seemed to work without warnings, but I have a feeling that I might have stublmed into a loophole.