Skip to content

fix(ios): Initialize Unity in layoutSubviews for Fabric support#174

Open
amitpdev wants to merge 1 commit intoazesmway:mainfrom
amitpdev:main
Open

fix(ios): Initialize Unity in layoutSubviews for Fabric support#174
amitpdev wants to merge 1 commit intoazesmway:mainfrom
amitpdev:main

Conversation

@amitpdev
Copy link

@amitpdev amitpdev commented Nov 7, 2025

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.

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.
@TackJordy
Copy link

Thank you so much!! Wasted so much time because of this issue

@jamie-currie
Copy link

Went from a blank screen to working straight away with this tweak thanks

@21pdavis
Copy link

Thanks for this! I also spent so much time trying to get this working and this has fixed my issue on iOS, as well.

@21pdavis
Copy link

21pdavis commented Feb 12, 2026

@amitpdev
Could I ask how you discovered this issue? Just curious - was there a debugging menu or view you were able to activate to see what was going on behind the scenes? That was my biggest issue in debugging this: not knowing what was actually happening and just getting a blank screen with no feedback.

@SethCram
Copy link

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...

@21pdavis
Copy link

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. 🤷‍♂️

@jamie-currie
Copy link

jamie-currie commented Feb 21, 2026

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

@TruAmbition
Copy link
Collaborator

TruAmbition commented Feb 21, 2026

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?

@SethCram
Copy link

@TruAmbition this worked for me on Unity 2021.3.41f1, iOS 18.7.1, Xcode 16.4

@TruAmbition
Copy link
Collaborator

@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?

@SethCram
Copy link

@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

@jamie-currie
Copy link

jamie-currie commented Feb 21, 2026

Worked for me on:

“iOS”: 26.2
“unity”: 6000.0.60f1
"expo": "~54.0.31",
"react-native": "0.81.5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants