Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Data exchange between HTML5 build and JS

I was wondering is there a way to exchange data between HTML5 game build and JavaScript in the browser?

The official documentations says that Unreal uses emscripten to compile C++ code to JS, and emscripten itself seems to have ways to expose functions to JS and to call inline scripts:


However, I haven't found any info on how to use these functions in my Unreal C++ code. I am relatively new to the engine as well as C++ in general, so I don't feel confident enough to do any experiments myself yet, but maybe someone has already tried to do something similar?

Say, I would like to type a name to an HTML form and then display it in my game — how would I do that?

Product Version: UE 4.17
more ▼

asked Aug 25 '17 at 08:32 AM in Everything Else

avatar image

6 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

UE4 does feed all user C++ files through the Emscripten compiler, so it should be possible to just type in Emscripten-specific code. Something like:

 #ifdef __EMSCRIPTEN__
 #include <emscripten.h>
 int someFunc()
 #ifdef __EMSCRIPTEN__
   EM_ASM(console.log('hello, this is from Javascript'));

To get a string from JavaScript land, you can do something like

 void someFunc()
 #ifdef __EMSCRIPTEN__
   char utf8StringInCHeap[256];
     var javaScriptString = "from JavaScript";
     stringToUTF8(javaScriptString, $0, $1);
   }, utf8StringInCHeap, 256);
   printf("This is a string: %s\n", utf8StringInCHeap);

The stringToUTF8(javaScriptString, memoryAreaInHeapForString, memoryAreaSize); function takes a JavaScript string and converts that to UTF8-encoded form in UE4 heap area. UE4 internal logging functions often like to take in UTF32, so further converting UTF8 to UTF32 may be needed depending on where you are pushing the string to.

more ▼

answered Aug 25 '17 at 11:24 AM

avatar image

1.2k 15 4 17

avatar image Laokoon Aug 25 '17 at 11:38 AM

That's a place to start, thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question