Unreal.js

Great plugin, but I have one quastion, is it possible to show html page with this plugin?

@Legolax Do you want to show real HTML page? For HTMLs, simply using WebBrowser widget would do the job. If you want to build your own mark up language with HTML tags, you can build HTML renderer which can render HTML to UMG’s. (Parsing HTML with some js HTML parser like htmlparser - npm)

I`d like to use HTML as Interface, and make js event like “onClick” accessible in blueprint or C++

@Legolax HTML is an old day tech. What about angular.js or react.js? There is poc of react.js + unrealengine (React-umg, GitHub - drywolf/react-umg: A React renderer for Unreal Motion Graphics (https://docs.unrealengine.com/latest/INT/Engine/UMG/)). Actually I’m doing entire UI coding with umg.js. :slight_smile:

you are right, but I have the interface like webpage on angular, but how could I connect it to anreal and get event of Onclick and sand some data to this page?

@Legolax have you seen react-umg I mentioned above? It might give you a clue. :slight_smile:

@nako_sung, yeah Ive looked at it, but never used it before, Ive tried to use an example of react.js connected via unreal.js but no result, it shows me nothing(( Id like to ask about little help about that, maybe there is another worked little example of that?) Becouse I cant find a way in wich I can move in this job :slight_smile:

@Legolax In fact my colleague is working on react-umg and he’ll make it as an open source project within weeks. Please stay tuned!

@nako_sung, thanx a lot for your answers, that was very helpfull :slight_smile:
I was very glad to discuss it with you :slight_smile:

Hey @nako_sung -

Got a few questions -
I am looking at having a custom Node.JS game server integrated into Unreal Engine via Unreal.JS.

Would having a game server in Node.JS be advisable? From what I understand as long as I do not do anything “complex” such as physics or whatever I should be good. Is this the case?
We are looking at having atleast 100 Players hopefully more on the server at once. Would Unreal JS / NodeJS be able to handle this?

Here is the game server we will be using -> http://gamestd.io/colyseus/

Just curious,
HeadClot

Edit: Added the server technology I will be using.

@HeadClot Communication between unreal.js and node.js isn’t well supported. There is WebSocket support only for windows platforms, but it is aimed to be high-performing. Instead of using websocket, you may expose tcp or udp socket functionalities which are available on UnrealEngine to Unreal.js. :slight_smile: btw regarding your question, I think unreal.js clients can do exactly what web browser clients can do (even more).

Hello, @nako_sung. First, thanks a lot for this great plugin, it makes a huge difference.

I’ve been exploring Unreal.js recently, but I don’t see examples addressing one particular setup I need, which seems trivial to me. Basically, I have an RPG dialogue editor and C++ dialogue system code from my previous projects, and I’d like to reuse them with Unreal. In dialogue editor, designers would type in various conditions (in local script language, but text expressions, basically, so they will be in JS now). For example, “getMoney() > 150”. Later, during a runtime, this text would be evaluated by script engine to return a boolean value.

Basically, that’s all I need, but what is the shortest way to call JavaScript’s eval() from blueprints or C++? Also, will eval() handle calls to blueprint functions (declared in c++ or BPs)? Following the examples on github, I thought about extending some actor class in JS, adding an overridden member function to it, which would finally call eval() inside, but I feel it’s a cumbersome noobish way to do this. Any advice? Thanks in advance.

If nako_sung is not around, maybe someone else has enough experience to answer this question?

@Flashback I hope you have nice time with unreal.js!

All you need to get it working is like below:

  1. Create a BP and add an blueprint implementable event. (Signature: (Actor*) -> bool)
  2. Inherit the BP you just created in your javascript and override that function.
class YourJS extends Blueprint.Load('YourBP...').GeneratedClass {
  YourEvent(actor) {
    return call_your_js_func(actor)
  }
}

That sounds like a plan, I’ll give it a try. Thank you!

Hi again. Since I’d prefer to avoid spawning any actor just to evaluate a script string, I found this question at your GitHub:

[Question] Running script from blueprint without attaching to actor

…with this solution:

So I connect this blueprint setup to keypress event, and instead of JavascriptContext’s RunFile function I use RunScript. I now can execute a script on keypress, and receive its return value via pin. Awesome! But:

  1. It significantly lags each time, probably because the JS script engine is initialized anew each time. So the obvious solution would be to store the reference to JavascriptContext after it’s created once. I can create an Object Reference variable and save there a return value of CreateContext. But I cannot cast it back to JavascriptContext, probably because it’s not UCLASS(BlueprintType). What do I do? How do I grab a reference to this context thingy to feed script strings to it when I need?

  2. “Expose”. The scope of what it RunScript sees, how do I define it? Say, if I have my own blueprint function library in C++, and a “getMoney()” function in it, will RunScript be aware of that function and will it process “getMoney() > 100” correctly? If not, how to achieve this?

Thanks.

So, posting some of my findings for someone who may find this interesting:

  1. Inability to store and reference JavascriptContext object. I guess one could eliminate this problem by adding BlueprintType specifier to the C++ class itself, but it would mean recompiling the plugin and potentially breaking something. I prefer to avoid that, so if you’re like me, you’d create JavascriptContext in C++ code and store a pointer to it in a singleton or wherever you want. Here is how JavascriptComponent does it:

auto Isolate = NewObject<UJavascriptIsolate>();
auto Context = Isolate->CreateContext();

JavascriptContext = Context;

Context->Expose("Root", this);
Context->Expose("GWorld", GetWorld());
Context->Expose("GEngine", GEngine);

  1. Make JavascriptContext see your blueprint functions. This works automagically for C+±defined blueprint function libraries. You may need to re-open the project, but other than that scripts like “MyBlueprintFuncLib.MyFunc();” run just fine. The situation with BP-defined blueprint function libraries isn’t as good, though - it’s not picked up automatically, and I can’t pass a reference of it to Expose, since there isn’t any instance of it. Or, at least, I don’t know how to grab a pointer to it from C++. So the workaround that comes to mind is using something spawnable (Actor?) as blueprint library and pass the pointer to it to Expose(). However, I haven’t tried this approach yet.

@nako_sung, feel free to correct me if I’m following the wrong trail or giving bad advice here.

@Flashback, 1) Adding BlueprintType decorator to UJavascriptContext isn’t a big deal, so why don’t you try adding decorators and recompile plugin? (Of course you could make a PR for this decorators)
2) Do you mean that YourBlueprintFuncLib.MyFunc() isn’t being picked up automatically? Your functions can be accessed as static functions, so you don’t have to expose any instance of your BP class.

If that doesn’t break a compatibility with your future updates, sure =)

If MyBlueprintFuncLib is decleared in C++, it’s picked up automatically. If it’s created as a blueprint in Content Browser, it isn’t.

1.png

3.png

4.png

I just dowloaded and installed this plugin from the Marketplace. I’m having issues launching Unreal on macOS 10.11.6 with this plugin installed. I get the following error

“Plugin ‘UnrealJS’ failed to load because module ‘V8’ could not be loaded. There may be an operating system error or the module may not be properly set up.”

Do I need to install something other than the plugin from the Marketplace? If so it would be nice if that were indicated in the Marketplace page to avoid confusion.

I just tried to build the plugin using the instruction on your site an still get the same error Can anyone let me know what I need to do to get this plugin installed properly?