Repository navigation
Field report: Unity as a Library in a SwiftUI app built with xtool on Linux #423
gulian
started this conversation in
Show and tell
Replies: 1 comment 1 reply
|
This is great, thanks for sharing. I have WIP changes for Xcode project support + closer parity when packaging, so would be interesting to revisit once those land. Might even be able to skip the xcframework step. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, and thanks for xtool. I wanted to know if a real-time Unity scene could live inside a SwiftUI app without a local Mac, and since it worked, here are my notes in case they're useful to you or to anyone trying the same thing.
Short version: it works. xtool 1.24.0 on Linux builds, signs and installs a SwiftUI app that embeds Unity 6 as an
.xcframework. The app runs on an iPhone with a 3D scene behind the SwiftUI UI, and it's been smooth in use. A Mac is still needed once, to compile the framework itself, but a GitHub Actions runner does that fine.The chain
BuildPipeline.BuildPlayer.macos-26runner (Xcode 26.6) compiles theUnityFrameworkscheme unsigned, copies the export'sData/folder into the framework, then runsxcodebuild -create-xcframework. About 4 minutes.Package.swiftdeclares it as a binary target:xtool dev build -c release, thenxtool install. Once the framework exists, a Swift-only change takes about 10 seconds to build. The app is around 300 MB.The framework step:
On the Swift side:
I then move
ufw.appController().rootViewinto aUIViewRepresentable, hide Unity's own window and callmakeKeyAndVisible()on the SwiftUI one. The app talks to the scene withsendMessageToGO. xtool signed the embedded framework without any special handling, which was the part I was least sure about.Things that bit me
Loggeroutput does. That left me debugging from the Swift side.Both are Unity's behaviour rather than xtool's, but you'll probably hit them if you try this.
One related note on #351: it says local installs aren't affected, but here they were. On an iPhone Duo the app opened in a centred compatibility window until I passed
-platform_versionwith the real SDK version at link time.What I haven't tested: anything beyond development signing, and only an iPhone Duo has actually run it so far. I also saw the app quit twice right after an install, with no crash report. It stopped happening and I never found the cause, so I can't say whether it's related to any of this.
If some of this is useful for the docs, feel free to use it.
All reactions