Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postMessage method not working #7

Closed
andreibosco opened this issue May 24, 2019 · 2 comments · Fixed by #13
Closed

postMessage method not working #7

andreibosco opened this issue May 24, 2019 · 2 comments · Fixed by #13

Comments

@andreibosco
Copy link

I'm trying to use postMessage to call a method on Unity and I'm getting the following error:

/MethodChannel#unity_view_0( 6284): Failed to handle method call
E/MethodChannel#unity_view_0( 6284): java.lang.ClassCastException
E/MethodChannel#unity_view_0( 6284): 	at io.flutter.plugin.common.MethodCall.argument(MethodCall.java:74)
E/MethodChannel#unity_view_0( 6284): 	at com.rexraphael.flutterunitywidget.FlutterUnityView.onMethodCall(FlutterUnityView.java:54)
E/MethodChannel#unity_view_0( 6284): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#unity_view_0( 6284): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88)
E/MethodChannel#unity_view_0( 6284): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:219)
E/MethodChannel#unity_view_0( 6284): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#unity_view_0( 6284): 	at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#unity_view_0( 6284): 	at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#unity_view_0( 6284): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#unity_view_0( 6284): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#unity_view_0( 6284): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#unity_view_0( 6284): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/flutter ( 6284): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, null, null)
E/flutter ( 6284): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 6284): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter ( 6284): <asynchronous suspension>
E/flutter ( 6284): #2      UnityWidgetController.postMessage (package:flutter_unity_widget/flutter_unity_widget.dart:44:14)
E/flutter ( 6284): #3      _UnityTestScreenState.build.<anonymous closure> (package:hydrocephaly_app/unity_test.dart:43:48)
E/flutter ( 6284): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
E/flutter ( 6284): #5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566:30)
E/flutter ( 6284): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
E/flutter ( 6284): #7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
E/flutter ( 6284): #8      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)
E/flutter ( 6284): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
E/flutter ( 6284): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 6284): #11     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 6284): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221:19)
E/flutter ( 6284): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
E/flutter ( 6284): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 6284): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 6284): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 6284): #17     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 6284): #18     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 6284): #19     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 6284): #20     _invoke1 (dart:ui/hooks.dart:233:10)
E/flutter ( 6284): #21     _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)
E/flutter ( 6284): 

This is how I'm calling it on flutter:

_unityWidgetController.postMessage("Cube", "ChangeObjMaterial", "_");
@juicycleff
Copy link
Owner

Did you see the demo example usage?

@thomas-stockx
Copy link
Collaborator

The demo example didn't use postMessage (which wasn't working). I've opened a pull request with the fix.

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 a pull request may close this issue.

3 participants