juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 518 forks source link

Fix incomplete iOS export after build target switch. #838

Closed timbotimbo closed 1 year ago

timbotimbo commented 1 year ago

Description

Clicking 'Export iOS' while on a different build target (like android) will result in an incomplete export.
The same might happen from the command line if -buildTarget iOS is omitted from the arguments.

This results in errors like Value of type 'UnityAppController' has no member 'unityMessageHandler and Value of type 'UnityAppController' has no member 'unitySceneLoadedHandler.

This issue is a sequel to #782, and might be a cause for issues like #426 #377 #486 #756 and more.

Problem

The build script will switch to iOS using SwitchActiveBuildTarget() and then continue the export.
However #if UNITY_IOS still returns false during this export, which ensures some code in XcodePostBuild will never be executed.

Unity needs a full recompile to change #if UNITY_ values, which can't happen within the same function.

Solution

I tried multiple approaches that wait for and detect a recompile, but none were reliable in all supported Unity versions.

In the end I decided to show a dialog requesting the user to run 'Export iOS' again, after the buildtarget has switched and scripts have been recompiled.

Type of Change