I’d like to add a couple of additional .swift files which UESwift.swift can reference to add some additional functionality.
Unlike a typical Swift project where if you add in Swift files through Xcode, they link through, it appears that the Unreal generated Xcode project does not recognize files in the same folder during the build and reports an error.
Is there a way to make sure that the build process picks up on these files within the folder when building an Unreal project to VisionOS?
Typical error when building in Xcode is:
[463/755] Compile [arm64] UESwift.swift /Users/userName/Unreal/Engine/Source/Runtime/Core/Public/Misc/CoreMiscDefines.h:276:43: expanded from macro 'UE_DEPRECATED' 15 | var body: some Scene { 16 | WindowGroup { 17 | ContentView() |
- error: cannot find ‘ContentView’ in scope
18 | }
19 | }`for reference, I have created a ContentView.Swift file and it’s referenced as follows in a modified version of UESwift.swift
`import Foundation
import SwiftUI
@main
struct UESwift: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}`
I don’t have a full answer on this, but I did figure out how to support additional swift files along side SwiftMain.swift, at least it seems to be working. Not certain this is 100% correct (particularly there could be dependency problems I’m unaware of)
But, i noticed that we are compiling the swift files one by one each into its own .o file. And there is no syntax to import or include or otherwise associate other swift files. I think how swift normally works is that you hand it all of the files in a single module and it compiles them together into a single module output file. So I changed the build tool so that as it processes all the swift files in a module together instead of one by one. And at that point my secondary swift file can be used from SwiftMain.swift.
As to using other modules. I believe that in swift that is where “Import” comes in, but I’m not certain how to get that working in unreal. In an ideal world we would presumably have unreal’s module dependency system automatically populate the import’s for swift… but it might be possible to do it manually. Important note: unreal’s module dependency system is already determining the build order, so even if you figure out how to do the import manually I think you would still need to follow the unreal dependency graph in order to reliably get correct builds.
Attached is that build change and my test setup, this is based on the dev-5.6 stream, would also work vs main.
Note: This change is not going into 5.6.