fix(ios): Initialize Unity in layoutSubviews for Fabric support#174
fix(ios): Initialize Unity in layoutSubviews for Fabric support#174amitpdev wants to merge 1 commit intoazesmway:mainfrom
Conversation
In Fabric mode, updateProps may not be called during initial render. Initialize Unity in layoutSubviews to ensure it starts when the view is displayed, regardless of prop lifecycle. Backwards compatible.
|
Thank you so much!! Wasted so much time because of this issue |
|
Went from a blank screen to working straight away with this tweak thanks |
|
Thanks for this! I also spent so much time trying to get this working and this has fixed my issue on iOS, as well. |
|
@amitpdev |
|
Fixed it for me! Is there any way we can get this merged into main? Doesn't look like this package is being actively maintained anymore... |
I just forked it with this change. Probably the best we can do for now. 🤷♂️ |
|
I created a patch using patch-package as a more local alternative to forking and you can move it project to project and also put it in your repo for others when they run npm install |
|
I can get this merged, would you please provide the iOS version, Unity Version and Xcode version and react-native version this has been confirmed working on? |
|
@TruAmbition this worked for me on Unity 2021.3.41f1, iOS 18.7.1, Xcode 16.4 |
Thank you. One more thing, what version of react-native are you running? |
react-native 0.81.5 |
|
Worked for me on: “iOS”: 26.2 |
Problem
When using React Native's new architecture (Fabric), Unity fails to initialize on iOS because updateProps is not reliably called during the initial component render cycle. This happens when:
No props are explicitly passed to the Unity view component
Props don't change between initial renders
The component uses only event handler props
This results in Unity never starting, showing "N/A" for SDK version, and games not loading on iOS devices.
Solution
Initialize Unity in layoutSubviews instead of relying solely on updateProps. The layoutSubviews method is always called by the iOS view system when a view is about to be displayed, making it a more reliable initialization point.
The check if(![self unityIsInitialized]) prevents double-initialization, ensuring this works correctly in both Fabric and the old architecture.
Testing
✅ Tested on real iOS devices (iPhone 15 Pro) with Fabric enabled
✅ Unity now initializes correctly and games load properly
✅ SDK version is correctly reported
✅ Backwards compatible with old architecture (Paper)
Related Issues
This addresses the root cause of Unity not initializing in Fabric mode, which may be affecting other developers using the new architecture but not yet reported.