Once you have successfully compiled and exported your project using Luna, you will be able to test and review your playable in the browser.
The Luna develop build is structured in the following way:
index.htmlhandles the loading and displaying of the playable content
UnityEngineincludes our implementation of the Unity Engine API interface
script6include internal engine code, and are minified
Using Chrome DevTools
In order to successfully understand and fix these errors, we recommend using the Chrome browser and powerful developer tools provided.
For more information and guides, please refer to the Google Chrome DevTools documentation.
To get started:
- Build a develop build from Luna.
- Start the server which will automatically open a tab in your browser.
Once open you will be presented with a spilt browser that will give a breakdown of the processes from the page. If there is an error it will be shown here.
Browser Error Types
The scene will run, but these could be things that may have been changed or altered during the conversion to JS. Typically, these shouldn't be any cause for concern, but of course you should review them, if these are the only messages, incase unintended problems occur.
These are runtime failures - usually it's easy to identify which code is the problem. Typically, you can click the error and be presented with more information including a stack trace in Chrome dev tools. See below for more information.
Using DevTools dev tools.
When debugging in Chrome, you will commonly use the Sources tab.
Let's look at each panel in the Chrome window to see what each section is used for and how to navigate it.
You can quickly open converted user code in the browser by typing command+shift+p and typing "UnityScriptsCompiler" and pressing enter. As mentioned above,
UnityScriptsCompiler.js includes all user scripts.
The File Navigator pane is on the left. Every file that the page requests is listed here. Clicking on a file will show the contents of the file.
The Code Editor pane is in the centre. After selecting a file in the File Navigator pane, the contents of that file are displayed here.
Luna Browser Error: Example 1
Here is an example error that you may encounter when using Luna, and how you can debug this using Chrome DevTools.
In the above example, the stack trace touches multiple script and also touches
UnityScriptsCompiler.js which contains all the converted (C#) user code.
UnityScriptsCompiler.js link in the stack trace will open this file and highlight the relevant line of code which you can use to trace where the error originated.
Once identified it should provide you with an idea of what to fix. In this case we can see the
Rigidbody is set to null. The solution is to make sure we have a
Rigidbody attached to our object in Unity.
Luna Browser Error: Example 2
A common error in the browser when using Luna is a
ctor error message. This can occur when scripts are attempting to call a constructor method from a script that might not be included in the build, is being called in the wrong execution order or is an un-implemented method.
When debugging this, it's helpful to identify where this code is being called from the user code. A few common things to consider for
- Is the call is in a script that may have been excluded?
- Is the call being made in the right execution order?
- Is the method implemented method in Luna?
In this example we can check the code by following the stack trace and identifying that the error originated in the
Awake method from our converted C# code (which as mentioned before is contained in
At the top of the stack trace there is also an
UnityEngine.js call, which defines Luna's implementation of the Unity engine. As shown in the second image above we can see that the method being used in the
Awake method is not yet implemented in Luna.
In most cases, it is simple to work around an un-implemented method. Here,
Screen.currentResolution can be replaced with a method that gets the resolution of the screen by using
Screen.height, which are supported methods in Luna.