Open bdeweygit opened 1 year ago
Amazing thanks. I will keep this open and try to write that somewhere, citing you. Unfortunately I do not use Unity anymore, and Swift / iOS even less
After some more investigation into the problem I found a much more correct and safe solution that does not require editing Unity's code and the potential unknowns that come with messing with its view and controller hierarchies. I'll try to put together a pull request over the next couple of weeks. Solution involves putting an observer on the Unity window's root view controller as a trigger to make our subview at the proper moment and avoid the race condition, as well as react to any subsequent overrides, not that I think there are any but who knows.
From the README
The problem is a race condition. In
public func show(controller: UIViewController)
we add Unity'srootView
as a subview of our own custom view controller, but when we start running Unity it will automatically add it as a subview of its own internal view controller. One overrides the other, so whoever runs last wins. Maybe you can find some way to wait for Unity to complete this step, ensuring youraddSubview
call always occurs last.For me, I've had to edit Unity's source code for a number of unrelated reasons, so the most natural thing was to just go directly to the line that assigns the view and comment it out. In the build output of project made with Unity version
2021.3.18f1
, go toClasses/UI/UnityAppController+ViewHandling
and replace thewillStartWithViewController
method with this.I would make a PR for you but the Unity iOS build output is not included in this repo.