Search code examples
unity-game-engineairconsole

AirConsole Unity plugin - WebGL build does not work while Unity debugger works


We've created a small demo of Unity3D with AirConsole-plugin which is working in Unity debugger. (If I press play, the browser opens, sometimes it works, sometimes it doesn't. If it doesn't, one can restart Unity and then it works.) If we create a release or a developer build, it does no longer work. It will load the image correctly, but the controllers (virtual+phone) stay 'loading' most of the time. Sometimes they reach the first correct HTML page, but then the message they send doesn't seem to arrive on the screen-side. When I click the 'Open Exported Port' after the build, it doesn't work too, except for once.

One error message I got once: "Uncaught TypeError: Cannot read property 'postQueue' of undefined"

This error message appears always: "pre-main prep time: 176 ms UnityLoader.js:1 Module.printErr @ UnityLoader.js:1"

Do you know what these error messages mean?


Solution

  • I've tried a lot, but this seems to solve the problem: Be sure to attach the event listeners in the Awake method, as they do in basic example application.

    public class AirConsoleService : MonoBehaviour
    {
        void Awake()
        {
            // register events
            AirConsole.instance.onReady += OnReady;
            AirConsole.instance.onMessage += OnMessage;
            AirConsole.instance.onConnect += OnConnect;
            AirConsole.instance.onDisconnect += OnDisconnect;
            // etc. ...
        }
        // etc. ...
    }
    

    My problem was that my AirConsoleService was static and not a MonoBehaviour to be sure that there is only one instance of AirConsoleService. It works perfectly for the debug 'play' mode, but in the release build, the AirConsole somehow does not know the deviceID which sent the message (this means, we get -1 from method ConvertDeviceIdToPlayerNumber. And this explains why the controllers don't get any signal from the screen.

    My solution: I've attached it as a component to the AirConsole object.

    Further notes:

    • Anti-Virus may block content.
    • Your PC/server has to be fast.
    • During development, log the deviceID and the playerID and the current active deviceIDs.
    • Often restart Unity or the integrated webserver of the plugin