Dispatching custom blueprint events via Javascript

I’m currently trying to find a way to make the custom blueprint events (or delegates from c++) visible to javascript.

After exporting I want to be able to make a call for these event, something similar to request_fullscreen_callback from HTML5OpenGL.cpp, but I could not solve how to bind the blueprint class to emscripten.

I tried to embind c++ classes without success. Default C++ classes are ok, blueprint classes, I have no idea how to accomplish.

Here is a case to make the question a little more understandable:
Let’s say that there is a point light in the scene and a button inside a widget. When a user releases the button, an event fires. On blueprint, the event is assigned and point light is turned on or off.

I want to replace the widget button, and instead use an HTML dom object instead. So when user releases the dom object, I want to trigger the same (or something like that) event to turn the point light on or off.

Is there any examples in UE4 code that I can check? Is this possible?

I’ve solved this by trying to simplify the problem. I wrote a blueprintable C++ class that calls a JS function on each tick and checks if any messages (JS array with json data) is waiting, receives any waiting data and acts accordingly (populates data on UE4 side, calls delegate, etc). It works very well and does not crash the speed of the game or system. If anyone needs something similar, just ask here :slight_smile:

Hi there, I believe I’m trying to accomplish something similar (based on your description). What did you have to configure in order to get your game to call Javascript from the C++ classes?

In context, I’m building a game to export to HTML5 and I want to make some calls to the browser’s api, but I’m just now looking at how that might work. Any guidance that you can give would be very helpful. Thanks!

you can use emscripten’s methods for calling js methods ( c++ >> js calls ). check this url out for details. Check out the emscripten_run_script parts. You can send a stringified json to js part, parse the string and use as data.

js >> c++ part is a little hard to incorporate if you are not compiling ue4 by yourself. you’ll need to add a few modules to emcc by yourself. but there is also a simpler solution.

  • write a notification / message system on js side that fills an array with whatever you want (maybe json objects, something like { action: “do-something”, data: { … } } )
  • write a blueprintable c++ source that calls the methods of the notification system with “emscripten_run_script” to check if a message is waiting, or to get the next message.
  • from blueprint use these methods and on each tick ask for a message (blueprint can ask for a specific action marked message and receive it, by this way every blueprint can tick for messages), then do whatever you want to do.

this will solve the problem and does not cause any slowness on html5 part. every blueprint can ask for a specific type of message, and receive the answer.

it seems hard to accomplish, but it simply depends on your js knowledge at this point. c++ and blueprint part are easy.

check https://github.com/ufna/VaRest if you do not know how to work with json + ue4 on c++ part.