Search Unity

Using jslib cause EntryPointNotFoundException in editor

Discussion in 'Web' started by Thaina, May 13, 2017.

Thread Status:
Not open for further replies.
  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    How can we test webgl jslib in the editor? Did you seriously force us to waste 10 minute to build whole webgl just for testing jslib?
     
    dan_ginovker and Novack like this.
  2. DukeRoderick

    DukeRoderick

    Joined:
    Dec 25, 2015
    Posts:
    15
    No, there's no way to test your jslib files outside of doing a build. If you really feel like its wasting your time then you could make an empty WebGL project and write a test class that uses your jslib file in some simulated way. You'll still need to do the builds but if you have no compression set in your build settings it should be a pretty quick process.
     
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    @DukeRoderick Empty project webgl still take too much time. I think most of the time it took come from unity engine itself. My project actually small with less than 10 script files. All model is asset bundle
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I agree that's far from an ideal workflow.

    For the time being, you could check your jslib with node (via command-line):
    /Applications/Unity/Unity.app/Contents/Tools/nodejs/bin/node <filename>

    you will get errors on mergeInto/autoAddDeps which usually are at the end of the file but that's expected in this case. You can just comment them out temporarily when doing that.
     
    Thaina likes this.
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    @Marco-Trivellato Sadly that seem like it not an option for me. Because what I need to test now is 3rd party system. I use firebase database javascript SDK in the jslib (It miraculously work fine). And now I could load and save data. But need to develop a real game with the datalistener system of firebase

    Are there any plan to fix this workflow in the next version yet?
     
  6. hschdl

    hschdl

    Joined:
    Aug 27, 2017
    Posts:
    3
    Hello, it's now 6 months later, I'd like to hear if there has been any improvements with regards to testing and debugging external javascript files ("jslib") within Unity editor?

    If someone sees that is just a minor annoyance please share your opinions too, because I share @Thaina 's opinion that having to build a WebGL project for testing a simple function is going to eat up my work week only doing that.

    @DukeRoderick could you share how long an empty WebGL takes to build in your setup?
     
    MilenaRocha and Novack like this.
  7. hschdl

    hschdl

    Joined:
    Aug 27, 2017
    Posts:
    3
  8. jvogt

    jvogt

    Joined:
    Sep 12, 2016
    Posts:
    1
    still no update on this?
     
    MilenaRocha and Novack like this.
  9. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Joining the club here. We need a real world case escenario for testing!

    Maybe we can have an option to enable a special play using a cached deployment where the game in the editor is set to interact with that instead of just playing on isolation.

    Having the play session separated from the actual context that the build will have in the real world is far too limiting!

    This "workaround" of making a build each time, just to find out you need to add a small change... then re-build, and so on. Oh lordy.
     
  10. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    The current workflow is far from perfect, but you can make sure to put code as minimum as you can in the .jslib and instead use as much as you can .js outside of unity. Then, if it's important for you to bundle files in unity, put the JS code in .jspre file
     
  11. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    844
    Having the javascript as external libraries or integrated with the build makes no difference whatsoever for the case. Its not entirely clear to me why do you even suggest that, but the problem is not making sure the javascript code works, there are other methods for that.

    The problem is testing the interaction of the unity project with the browser side javascript, which wont happen when you play the project within the Unity Editor, but require a build even for the slightest of tests. This makes the development iteration quite painful and time wasting.

    Maybe if some Unity Editor embeded javascript engine (just for the purpose of mimic'ing the browser) could serve the jslib code to the in-editor play sessions of WebGL projects, that would be a killer.
     
    bobbaluba and Thaina like this.
  12. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    Yeah it's seriously stupid that as of 2019 we even have project tiny but editor just don't integrate js emulator to be test in their environment
     
  13. UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    Joined:
    Jun 19, 2018
    Posts:
    23
    It is very easy to bypass. I made an interface to call jslib, than made two classes, one for build and another for editor.
    Then I use Application.isEditorat at the beginning of the game to create one or another class.
    All my code calling interface
     
    Last edited: Jun 7, 2019
    De-Panther likes this.
  14. Steamc0re

    Steamc0re

    Joined:
    Nov 24, 2014
    Posts:
    144
    Can you share that?
     
  15. UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    Joined:
    Jun 19, 2018
    Posts:
    23
    For example you have such .jslib
    Code (JavaScript):
    1. mergeInto(LibraryManager.library, {
    2.  
    3.     SendToBrowser: function (json) {
    4.         window.UnityMessageHandler(Pointer_stringify(json));
    5.     },
    6.  
    7. })
    Here is code
    Code (CSharp):
    1. using System;
    2. using System.Runtime.InteropServices;
    3. using UnityEngine;
    4.  
    5. namespace Demo
    6. {
    7.     public class WebController
    8.     {
    9.         private readonly INotifier notifier;
    10.  
    11.         public WebController()
    12.         {
    13.             if (Application.isEditor)
    14.             {
    15.                 notifier = new EditorNotifier();
    16.             }
    17.             else
    18.             {
    19.                 notifier = new BrowserNotifier();
    20.             }
    21.         }
    22.  
    23.         public void SendDataToBrowser(string type, string body)
    24.         {
    25.             notifier.Notify(type, body);
    26.         }
    27.  
    28.  
    29.         private interface INotifier
    30.         {
    31.             void Notify(string type, string body);
    32.         }
    33.  
    34.         private class EditorNotifier : INotifier
    35.         {
    36.             public void Notify(string type, string body)
    37.             {
    38.                 Debug.Log($"Called js with type: {type} and message: {body}");
    39.             }
    40.         }
    41.  
    42.         private class BrowserNotifier : INotifier
    43.         {
    44.             /// Same as in *.jslib file
    45.             [DllImport("__Internal")]
    46.             private static extern void SendToBrowser(string json);
    47.          
    48.             public void Notify(string type, string body)
    49.             {
    50.                 var message = new ReqMessage
    51.                 {
    52.                     type = type,
    53.                     body = body
    54.                 };
    55.  
    56.                 SendToBrowser(JsonUtility.ToJson(message));
    57.             }
    58.         }
    59.  
    60.         [Serializable]
    61.         private struct ReqMessage
    62.         {
    63.             public string type;
    64.             public string body;
    65.         }
    66.     }
    67. }
    Here is example how to use.
    Code (CSharp):
    1. var webController = new WebController();
    2. webController.SendDataToBrowser(type, body);
     
  16. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    @UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582 Everyone could do that man. BUT THAT NOT WHAT WE SHOULD DO. Because we want to see the behaviour of the real js SDK we include in our library too. Please stop being naive

    You can go write your firebase SDK mocking class yourself. I won't waste time do it. It was the unity editor that should be able to call jslib directly in its editor
     
    Novack and Stnaire like this.
  17. UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582

    Joined:
    Jun 19, 2018
    Posts:
    23
    Sorry bro, I just answered Steamc0re question.
     
  18. leon-do

    leon-do

    Joined:
    Jul 6, 2020
    Posts:
    4
    it's 2020. Any updates?
     
    MilenaRocha, pragmascript and Novack like this.
  19. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,165
    It seem like unity has given up on the idea of running webgl in its editor already and I think unity encourage us to use unity tiny for web platform instead. Unity tiny drop support on running in editor and try to have us launch the debug in real platform (in other word, just build and run web game in your browser directly)
     
    MilenaRocha likes this.
  20. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Just stumbled to this thread, and reading the posts above violate community contribution guidelines in more than one way, so I am closing this thread. Please be respectful and goal-oriented when discussing with other forum members.

    Unity unfortunately currently does not have a solution in place to embed a JS engine into the editor. That is an interesting idea, although that would come with a lot of restrictions and differences in place compared to running in a real browser, so not sure if people would really be happy with such an attempted solution.

    To iterate on JavaScript code without having to rebuild, there is a somewhat simple workflow that I would recommend that works for many development scenarios. If one does a Development build, all the code in the .jslib files that are called by C# code will be present in the generated build.framework.js file. What one can do is to then edit that code file directly, and use browser's F5 refresh to live-reload the changes to the executing build. Then when one is satisfied with the changes, copy all the changed code from build.framework.js file back to the source .jslib file.

    That way iteration on the JS code can be achieved without needing to rebuild the project every single time (although one will still need to rebuild when iterating on the C# <-> JS language marshalling boundary itself)

    In any case, closing this thread, the above text is not something we wish anyone to need to read. Please open new threads with proper constructive tone if you would like to follow up with a conversation.
     
  21. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Closed from further comments.
     
Thread Status:
Not open for further replies.