flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
There's no way to release Unity resources
Describe the bug
There's no way to release resources used by UnityWidget. We are using Unity for an AR feature, and the second time you open the screen with a UnityWidget, camera lags a lot and there's no loading screen, meaning previous Unity resources were not released. Moreover, doing it 2/3 times fast enough crashes the app because it runs out of memory.
To Reproduce In the example app, you can see a similar behavior:
- Open rotation sample
- "Made with Unity" loading screen is shown
- Go back
- Open rotation sample again
- No "Made with Unity" screen is shown, the controller was not released/disposed properly
Expected behavior After disposing the controller, it should stop all Unity resources
Actual behavior
Disposing/unloading the controller doesn't help with resources, and calling quit closes the app.
Smartphone (please complete the following information):
- Device: OnePlus 5
- OS: Android
- Version: 10
Additional context
Also tried using openInNativeProcess and adding the extended activity in manifest, but that way we can't communicate with messages to the Unity process.
Same here. Every time I use UnityWidget a new instance was created and if I change scene in one of it onUnitySceneLoaded is called as many times it was loaded in each one of them.
I believe I am experiencing the same issue on iOS. For me, whenever another instance is created, Flutter stops receiving messages from Unity, whereas messages are being sent correctly to Unity. And, when enough instances are opened, Unity freezes.
any solutions. Facing the same issue
I believe I am experiencing the same issue on iOS. For me, whenever another instance is created, Flutter stops receiving messages from Unity, whereas messages are being sent correctly to Unity. And, when enough instances are opened, Unity freezes.
This is exactly what I am experiencing in iOS. Is there any explanation for this that could lead to a potential solution? @juicycleff @thomas-stockx @jaboyc
@OGmetamonkey please use v4 branch, mind you it's still in alpha. Will make an alpha release officially this week
@OGmetamonkey please use v4 branch, mind you it's still in alpha. Will make an alpha release officially this week
Tried it out. I keep getting project/ios/Runner/Runner-Bridging-Header.h:2:9: 'UnityUtils.h' file not foundwhen using xcode to build the project. Any idea what's going on? @juicycleff
Rebuilt it three times while implementing every step to try and find the problem. No dice.
Output:
Xcode's output: ↳ Development/project/flutter-unity-view-widget-4/ios/ Classes/FLTUnityView.swift:10:8: error: no such module 'UnityFramework' import UnityFramework ^ Command CompileSwift failed with a nonzero exit code Command CompileSwift failed with a nonzero exit code Command CompileSwift failed with a nonzero exit code note: Using new build system note: Building targets in parallel note: Planning build note: Constructing build description
Encountered error while building for device.
Hi @juicycleff , I just tried the latest commit of V4. I still get these errors when trying to compile for iPhone:
Development/project/ios/Runner/Runner-Bridging-Header.h:2:9: error: 'UnityUtils.h' file not found #import "UnityUtils.h" ^ 1 error generated.
:0: error: failed to emit precompiled header '/Users/metamonkey/Library/Developer/Xcode/DerivedData/Runner-dgqsyzbbuoeoncgvconxvpyumojg/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_2GZ4YKJM5Z610-clang_D1FYERE3G02L.pch' for bridging header 'Development/project/ios/Runner/Runner-Bridging-Header.h' 2 errors generated.
I noticed there is a typo in step 3 and 4 of the iOS setup (shown below). Did you intend to remove step 3?
- Add this to your Runner/Runner/Runner-Bridging-Header.h 4. Add to Runner/Runner/AppDelegate.swift before the GeneratedPluginRegistrant call:
@OGmetamonkey Please look at the readme in v4 branch. You need to remove unityutils.h

@juicycleff I'm having trouble understanding that. Am I looking at the right thing?
@OGmetamonkey I just updated the readme
@juicycleff So that actually allowed the app to build on VS Code, but still not on XCode, and when running in VSCode it's crashing when Unity is launched. 'exited sigterm'
So I tried to run 'flutter build ios' and I get the following errors:
Error output from Xcode build: ↳ ** BUILD FAILED **
Xcode's output: ↳ Command CompileSwift failed with a nonzero exit code Development/project/flutter-unity-view-widget-4/ios/Classes/FLTUnityView.swift:10:8: error: no such module 'UnityFramework' import UnityFramework ^ Command CompileSwift failed with a nonzero exit code Command CompileSwift failed with a nonzero exit code note: Using new build system note: Building targets in parallel note: Planning build note: Constructing build description
Encountered error while building for device.
@Zazo032 sorry for the late reply, but you navigating away from unity widget screen does not remove unity resources, you should read up the unity as a library documentation. This has nothing to do with the flutter package. However, you can improve this by navigating to an empty unity scene, before leaving your current unity widget
@Zazo032 sorry for the late reply, but you navigating away from unity widget screen does not remove unity resources, you should read up the unity as a library documentation. This has nothing to do with the flutter package. However, you can improve this by navigating to an empty unity scene, before leaving your current unity widget
But there's no native way to "dispose" the Unity controller that is being used to be able to free resources?
@juicycleff So that actually allowed the app to build on VS Code, but still not on XCode, and when running in VSCode it's crashing when Unity is launched. 'exited sigterm'
So I tried to run 'flutter build ios' and I get the following errors:
Error output from Xcode build: ↳ ** BUILD FAILED ** Xcode's output: ↳ Command CompileSwift failed with a nonzero exit code Development/project/flutter-unity-view-widget-4/ios/Classes/FLTUnityView.swift:10:8: error: no such module 'UnityFramework' import UnityFramework ^ Command CompileSwift failed with a nonzero exit code Command CompileSwift failed with a nonzero exit code note: Using new build system note: Building targets in parallel note: Planning build note: Constructing build description Encountered error while building for device.
My log when I get the crash:
flutter: Unity is created!!with unityId: 0
flutter: *********************************************
flutter: ** flutter unity controller setup complete **
flutter: *********************************************
Lost connection to device.
@juicycleff So that actually allowed the app to build on VS Code, but still not on XCode, and when running in VSCode it's crashing when Unity is launched. 'exited sigterm'
So I tried to run 'flutter build ios' and I get the following errors:
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
Command CompileSwift failed with a nonzero exit code
Development/project/flutter-unity-view-widget-4/ios/Classes/FLTUnityView.swift:10:8: error:
no such module 'UnityFramework'
import UnityFramework
^
Command CompileSwift failed with a nonzero exit code
Command CompileSwift failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Encountered error while building for device.
My log when I get the crash:
flutter: Unity is created!!with unityId: 0 flutter: ********************************************* flutter: ** flutter unity controller setup complete ** flutter: ********************************************* Lost connection to device.
Did you properly import UnityFramework.framework just as the docs
I did. Tried multiple times just to be sure.
On Wed, Feb 10, 2021 at 11:54 AM Rex Raphael [email protected] wrote:
@juicycleff https://github.com/juicycleff So that actually allowed the app to build on VS Code, but still not on XCode, and when running in VSCode it's crashing when Unity is launched. 'exited sigterm'
So I tried to run 'flutter build ios' and I get the following errors:
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
Command CompileSwift failed with a nonzero exit code
Development/project/flutter-unity-view-widget-4/ios/Classes/FLTUnityView.swift:10:8: error:
no such module 'UnityFramework'
import UnityFramework
^
Command CompileSwift failed with a nonzero exit code
Command CompileSwift failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Encountered error while building for device.
My log when I get the crash:
flutter: Unity is created!!with unityId: 0
flutter: *********************************************
flutter: ** flutter unity controller setup complete **
flutter: *********************************************
Lost connection to device.
Did you properly import UnityFramework.framework just as the docs
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/juicycleff/flutter-unity-view-widget/issues/281#issuecomment-776856224, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5IQJEQLABXKUT4UDWUNWDS6K23XANCNFSM4VA4NNBA .
--
@OGmetamonkey dies this issue exist in the example because it just might be cached references issue
@juicycleff Sorry for delay. I both ran the fresh V4 example and tried to clean my own project. I ended up eliminating the previous problem in my project but getting 2 new errors. I got the same 2 errors in the example project. The errors below exist in both the example project and my current project:
Undefined symbols for architecture arm64: "_OnUnitySceneLoaded", referenced from: _NativeAPI_OnUnitySceneLoaded_m2F3C71B76C7BC469B27E51DB6FDD828BC2F54384 in Assembly-CSharp.o (maybe you meant: _NativeAPI_OnUnitySceneLoaded_m2F3C71B76C7BC469B27E51DB6FDD828BC2F54384) "_OnUnityMessage", referenced from: _NativeAPI_OnUnityMessage_m1CF7151340955DF0256F5C6AD708DBE71F45AFB5 in Assembly-CSharp.o (maybe you meant: _NativeAPI_OnUnityMessage_m1CF7151340955DF0256F5C6AD708DBE71F45AFB5) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is how I got my own project to that point:
- I completely eliminated all references to my unity integration and framework from xcode, deleted the unity library folder, deleted my pub cache, and cleaned my build (flutter clean and cmd+shift+k).
- I downloaded a clean FlutterUnityIntegration package and re-imported all those assets.
- I then made the necessary changes to build.cs that prevent the append error when building in unity.
- I then went step by step through the ios steps in the tutorial.
Like I said, same errors in both the example and my project. So I imagine your suggestion that it was a cache issue is correct. These errors may be unrelated to this current issue, but it seems to be a problem.
@OGmetamonkey oh this is simple, I was supposed to automate it. Will send you a quick fix a moment
@OGmetamonkey Made a push. I just enabled it. You will have to download the unity script package again. That should fix it for you. And try using unity 2019.4.3 or later as it contains a lot of unity as a player fix from unity
@juicycleff That worked!! With these changes, V4 fixes the messenger issue! Thanks so much!
hello.
@OGmetamonkey, how did you solve the problem?
flutter_unity_widget-4.0.0-alpha.2/ios/Classes/FLTUnityWidgetController.swift:9:8: No such module 'UnityFramework'
and i got another error - /ios/Runner/AppDelegate.swift:3:8: Could not build Objective-C module 'flutter_unity_widget'
Use the latest push on the V4 branch and do the following:
@klepov
- Completely eliminate all references to unity integration and framework from xcode, delete the unity library folder, delete the pub cache (usually hidden files in user folder), and clean the build.
- Remove the old FlutterUnityIntegration package from the unity project and download a clean FlutterUnityIntegration package from V4 and re-import all those assets.
- Go step by step through the V4 readme.
/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_unity_widget-4.0.0-alpha.2/ios/Classes/FLTUnityView.swift:10:8: No such module 'UnityFramework'
the error is still there unity 2019.4.3f1
Try Unity 2020.2.3f1
after updating the version of the unity - those errors are gone, but other errors appeared after build in xCode
Apple Mach-O Linker (ld) Error Group Undefined symbols for architecture arm64: "_UnityMC_NSString_serialize", referenced from: "_UnityMC_NSString_deserialize", referenced from: .... 25+ similar errors
Not sure. First thing I always try is a flutter clean from terminal and a cmd-shift-k in xcode.
@OGmetamonkey , your comments helped alot to resolve these errors. Thank you so much.
I can able to resolve these errors in the Unity Editor : 2019.4.22
@Zazo032 sorry for the late reply, but you navigating away from unity widget screen does not remove unity resources, you should read up the unity as a library documentation. This has nothing to do with the flutter package. However, you can improve this by navigating to an empty unity scene, before leaving your current unity widget
But there's no native way to "dispose" the Unity controller that is being used to be able to free resources?
I'd like to know the answer to this too please @juicycleff
Please use the version 2019.3.14 or later. But it also largely depends on how you use build you architect your game. Largely the unload function has never predictably work even after a conversation with the unity team behind UaaL
I know what's the error eventually.
Try this solution: https://github.com/Ahmadre/unity_widget#solutions-to-problems