-
Notifications
You must be signed in to change notification settings - Fork 17
Description
From the README
Between the moment you create the UnityFramework instance, and the moment you can display it, it seems like there is an issue. Some people try to add a delay, but this is definitely a hack.
The problem is a race condition. In public func show(controller: UIViewController)
we add Unity's rootView
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 your addSubview
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 to Classes/UI/UnityAppController+ViewHandling
and replace the willStartWithViewController
method with this.
- (void)willStartWithViewController:(UIViewController*)controller
{
_unityView.contentScaleFactor = UnityScreenScaleFactor([UIScreen mainScreen]);
_unityView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// original - our own superview could get replaced if set before this line runs
// _rootController.view = _rootView = _unityView;
// custom
_rootView = _unityView;
}
I would make a PR for you but the Unity iOS build output is not included in this repo.