Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

JavaScript Events

Aaron Shea edited this page Feb 21, 2015 · 1 revision

So you want to send information from your webpage back into Unreal Engine?

This is totally doable! BLUI has a built in multicast delegate that will fire on a special native function called blu_event

Let's say we want to send a "hello there!" message into Unreal Engine and log it to the viewport.

The HTML

<a href="#" onclick="blu_event('click_me','hello there!')">Click me!</a>

If you're not familiar with HTML attributes, setting href to # makes the link go nowhere. While the onclick attribute will execute the JavaScript snippet we place inside it (blu_event('click_me','hello there!')) when the link is clicked.

The blu_event JavaScript function

blu_event is a native JavaScript function that will fire an inter-process message into the parent UE4 process. BLUI will listen for these and notify the engine when something occurs.

blu_event takes two arguments - the event name and the event message. If you wanted to send an event called "damage player" and have it send a numeric value to the engine you'd write the following code:

blu_event("damage_player", 10);

The 2nd argument supports the following types: string, boolean, integer, double

Blueprint hook-up

If you drag off the BluEye instance pin you can assign an event that will be fired whenever blu_event is called.

Say we execute the following code in the web page:

blu_event("damage_player", 10);

And have a setup like this in blueprints:

The value of Event Name will be "damage_player" and the value of Event Message will be "10"

To distinguish between multiple events, simply check the event name in blueprints. Multiple events can be assinged to a single BLUI instance for organization and cleanness.

At this moment, you must convert the string back into the desired type (other than string) in UE4. This will be improved later in development