I’m digging into bridging SwiftUI and Unreal Engine in order to take advantage of what SwiftUI can bring to an Unreal VisionOS application (in particularly where eye gaze and UX interactions come out of the box which with eye gaze of example, simply isn’t present in Unreal VisionOS implementation).
Is it possible to get some clarity on how this is currently being implemented as UECppToSwift.h appears to be working some magic as if I define a function in that file and have the implementation somewhere else (like in my own custom plugin), this function is automatically exposed so that it can be called from UESwift.Swift quite trivially:
extern “C” void MySwiftCallingUnrealFunction()
I am however struggling to properly understand why this is happening and how I could move this definition to a custom plugin rather than an engine plugin and what may be needed to get this to work (as when I move this definition outside of UECppToSwift.h, the function call immediately crashes the application where SwiftUI can’t call the specially named function - suggesting there is something special with UECppToSwift.h which I don’t properly understand.
I’d also like to understand how to go the other way and call SwiftUI from Uneal C++. It appears that this can be done by creating an objective c .m file that can be used as an intermediary however this file needs to be able to call functions on the SwiftUI file and I don’t appear to be able to generate a bridging header for UESwift.Swift in the build process in order to do this. I’ve managed to get from Unreal C++ -> ObjectiveC .m file - it’s the link between an ObjectiveC file and UESwift.Swift which I can’t seem to get working.
It also appears from some of Apple’s recent developer documentation that it may be possible to skip ObjectiveC bridging entirely and enable some kind of Swift interop with C++ however these settings don’t appear evident in the VisionOS Xcode project that is generated for the Unreal project - which may be because the UESwift.Swift is only part of a larger Xcode project?
https://www.youtube.com/watch?v=MixEUoUQyNU
So in summary:
-
SwiftUI -> Unreal C++ - why does this work with functions defined in UECppToSwift.h and how can I do something similar without having to modify this file - ideally being able to enable this kind of interop from a project C++ plugin.
-
Unreal C++ -> SwiftUI - how can this be achieved given the Xcode project is substantially more complex than most typical code examples online and where the Xcode project is a bit more bespoke
It goes without saying that I’m working fully with a source build for this endeavor.