flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
In IOS, the onUnityMessage cannot be executed when entering the page for the second times
Such as the title
The temporary solution is as follows:
Modify plugin in controller.dart File. In the first line of the method:_connectStreams (int unityId) add Platform.isIOS?0 :unityId; And import ' dart:io ';
I'm having exactly this issue, I tried to implement your temporary solution but I couldn't implemented it, could you post more clear instructions on how do this? thanks in advance
Update: I think I resolve the issue What i did exactly using your instructions is:
- On file flutter_unity_widget.dart I add the import 'dart:io'; on the top part
- then on controller.dart I add on method _connectStreams the following line starting the method unityId = Platform.isIOS?0:unityId;
The reason for this problem is that each time you enter the unity page, you will return a new unityid. However, the onunitymessage with unityid = 0 still works on the IOS side.
If you are Android studio, you can find the plug-in source file by pressing the left mouse button of Ctrl + unitywidgetcontroller controller.dart .then on controller.dart I add on method _connectStreams the following line starting the method unityId = Platform.isIOS?0:unityId;
I Will make a release with a fix for this soon, with port to kotlin and swift
There is a bug in objc code, i forked a native project to resolve it.
even with the fix from @Darkmax, it still doesn't work for second time. Any idea?
Ok, just figured it out it. In stead of always 0 for ios, try 1 for unityID
Ok, just figured it out it. In stead of always 0 for ios, try 1 for unityID
I have the same issue as yours, "In stead of always 0 for ios, try 1 for unityID" as you say, do you mean change the unity ID every time when enter the same page?
@dantetwc @juicycleff I have found the reason about the case you met. See https://github.com/juicycleff/flutter-unity-view-widget/blob/master/ios/Classes/FLTUnityWidgetController.swift You can see the globalChannel always be the newest channel, and unity instance only sends message to globalChannel, so when you come back to the old page with unity widget controller, globalChannel still be the latest created channel and not the old page channel. I solve the issue by re-foucsing the old channel with unityId when the old page appears.
I didn't see this error in the current version, but @juicycleff @Ahmadre can you check if it's fixed?