No announcement yet.

Call C++ functions from JS

  • Filter
  • Time
  • Show
Clear All
new posts

    Call C++ functions from JS


    I need to be able to call C++ (or blueprint) functions from JavaScript. I know that Unreal uses Emscripten to pack the C++ code to HTML5 build. It should be integrated in Unreal, but it is still not clear to me how to actually use it. I am able to build my Blueprint / C++ app in HTML5 and run it, but I just don't understand how to call the C++ functions. According to this thread, it should be possible:

    But what I don't get is:
    - PLATFORM_HTML5_BROWSER is not defined at all. No matter if I run from editor or package the APP as HTML5, it is not defined. Am I supposed to do it myself? Because I would expect it to behave similarly as for example PLATFORM_WINDOWS...
    - those EMSCRIPTEN_KEEPALIVE and other EMSCRIPTEN macros are not defined. Am I suppose to include anything? I tried to include <emscripten.h>, but that fails right away when trying to build the editor so I cannot even get to packaging the app for HTML5.

    The best thing would be if there was some comprehensive tutorial for JS / C++ integration, but that doesn't seem to be the case. Or is it?

    Last edited by ArosPrince; 06-13-2019, 05:44 AM. Reason: Tags added

    OK, at this point, I was able to solve it by putting this in the cpp file:

    #ifdef __EMSCRIPTEN__
    #include <emscripten.h>
    #include <emscripten/html5.h>
    I don't know if this is the way to do it, but at this point I am at least able to package the HTML5 build.

    The next question however would be... I get this in the console when I run the app:

    'ccall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)
    Well, if I read the FAQ correctly it seems that it no longer exports all of the function in order to save some space. But I just can't see where would I add it in Unreal. I guess that would be some parameter to the emscripten execution... But where do I set it?