Search Unity

EntryPointNotFoundException in some functions of the same .jslib file

Discussion in 'Scripting' started by alphametaghost, Jan 4, 2020.

  1. alphametaghost

    alphametaghost

    Joined:
    Sep 16, 2018
    Posts:
    10
    Hello people!

    I'm trying to use some Javascript functions located in a .jslib file created by my own. This file is located in the Plugins folder as recommended. The project is being built over WebGL.

    Here´s the file:

    Code (JavaScript):
    1. mergeInto(LibraryManager.library, {
    2.  
    3.   AddNumbers: function (x, y) {
    4.     return x + y;
    5.   },
    6.  
    7.   OpenPageInNewTab: function (url) {
    8.     url = Pointer_stringify(url);
    9.     console.log('Opening link: ' + url);
    10.     window.open(url,'_blank');
    11.   },
    12.  
    13.   HideLoadingScreenFadeOut: function () {
    14.       let loadingScreen = document.getElementById("loading_screen").querySelector("img");
    15.     loadingScreen.classList.add("fade-out-bck");
    16.   },
    17.  
    18.   BindWebGLTexture: function (texture) {
    19.     GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[texture]);
    20.   },
    21.  
    22. });

    And this is the C# class that calls some of those functions:

    Code (CSharp):
    1. using System.Runtime.InteropServices;
    2. using UnityEngine;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class JavaScriptWebManager : MonoBehaviour
    6. {
    7.  
    8.     [DllImport("__Internal")]
    9.     private static extern void HideLoadingScreenFadeOut();
    10.  
    11.     [DllImport("__Internal")]
    12.     private static extern int AddNumbers(int x, int y);
    13.  
    14.  
    15.     void OnEnable()
    16.     {
    17.        
    18.            SceneManager.sceneLoaded += OnSceneLoadedFadeOutLoadingScreen;
    19.     }
    20.  
    21.     private void OnSceneLoadedFadeOutLoadingScreen(Scene scene, LoadSceneMode mode)
    22.     {
    23.         Debug.Log("LA SUMA DE ADD_NUMBERS ES: " + AddNumbers(4,5));
    24.  
    25.         HideLoadingScreenFadeOut();
    26.     }
    27.    
    28.     void OnDisable()
    29.     {
    30.         SceneManager.sceneLoaded -= OnSceneLoadedFadeOutLoadingScreen;
    31.     }
    32.  
    33. }

    The thing is, when I call the "OpenPageInNewTab" function in another script, it works perfectly but Unity doesn`t seem to be able to find the "HideLoadingScreenFadeOut" and "AddNumbers" functions in this script.
    Unity throws this error when I try to call those functions:

    EntryPointNotFoundException: AddNumbers
    JavaScriptWebManager.OnSceneLoadedFadeOutLoadingScreen (UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode) (at Assets/Scripts/JavaScriptWebManager.cs:30)
    UnityEngine.SceneManagement.SceneManager.Internal_SceneLoaded (UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode) (at C:/buildslave/unity/build/Runtime/Export/SceneManager/SceneManager.cs:220)

    Also, some errors show up when I try to build the project, making the build fail. This errors are related with the previous one I think because they don't appear in the console when I delete the lines related to those functions in the script.


    I would like to know why some functions work and some others don't.

    Thanks for your help!