react-native-unity icon indicating copy to clipboard operation
react-native-unity copied to clipboard

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

Open amitpdev opened this issue 1 month ago • 0 comments

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.

amitpdev avatar Nov 07 '25 13:11 amitpdev