Flutter unity communication issue

  arcore, c++, dart, flutter, unity3d

I an new to unity and I have a scene that I must integrate into a flutter app as part of my job (An AR scene). I connected the scene successfully but the problem is that the communication between flutter and unity is not working . The onUnitySceneLoaded & the onUnityMessage are not working. Only the onUnityCreated is working and displaying prints. To my understanding I need to add some code to the unity scene to make its messages be recognized by flutter and the Flutter unity package . So lets ignore this for know and investigate why is onUnitySceneLoaded not working. Shouldn’t it work out of the box automatically. This function will work directly after the unity scene appears right ?
Here is my entire flutter code for the unity screen:

import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

class UnityMainScene extends StatefulWidget {
  UnityMainScene({Key key}) : super(key: key);

  @override
  _UnityMainSceneState createState() => _UnityMainSceneState();
}

class _UnityMainSceneState extends State<UnityMainScene> {
  UnityWidgetController _unityWidgetController;

  @override
  void initState() {
    super.initState();
  }

  

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment(0.8, 0.0),
              colors: [
                const Color.fromRGBO(109, 180, 194, 1),
                const Color.fromRGBO(83, 116, 234, 1),
              ],
            ),
          ),
          child: Column(
            children: [
              Expanded(
                child: Container(
                  clipBehavior: Clip.antiAlias,
                  width: MediaQuery.of(context).size.width,
                  height: MediaQuery.of(context).size.height,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(50),
                        bottomRight: Radius.circular(50)),
                  ),
                  child: UnityWidget(
                    onUnityCreated: _onUnityCreated,
                    isARScene: true,
                    onUnityMessage: onUnityMessage,
                    onUnitySceneLoaded: onUnitySceneLoaded,
                    fullscreen: false,
                  ),
                ),
              ),
              Container(
                padding: const EdgeInsets.all(20.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    GestureDetector(
                      child: Image.asset('assets/images/wallet.png'),
                      onTap: () => Navigator.pop(context),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  void onUnityMessage(message) {
    print('unity message recieved by anass');
    print('Received message from unity: ${message.toString()}');
  }

  void onUnitySceneLoaded(SceneLoaded scene) {
    print('unity scene loaded by anass');
    print('Received scene loaded from unity: ${scene.name}');
    print('Received scene loaded from unity buildIndex: ${scene.buildIndex}');
  }

  // Callback that connects the created controller to the unity controller
  void _onUnityCreated(controller) {
    print('unity scene created by anass');
    this._unityWidgetController = controller;
  }
}

Source: Windows Questions C++

LEAVE A COMMENT