Announcement

Collapse
No announcement yet.

Unreal.js

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [MENTION=260]HeadClot[/MENTION] 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. btw regarding your question, I think unreal.js clients can do exactly what web browser clients can do (even more).

    Comment


      Hello, [MENTION=33973]nako_sung[/MENTION]. 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.
      Last edited by Flashback; 10-08-2016, 03:08 PM.

      Comment


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

        Comment


          [MENTION=157359]Flashback[/MENTION] 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.

          ```js
          class YourJS extends Blueprint.Load('YourBP...').GeneratedClass {
          YourEvent(actor) {
          return call_your_js_func(actor)
          }
          }
          ```

          Comment


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

            Comment


              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
              https://github.com/ncsoft/Unreal.js/issues/110

              ...with this solution:
              Click image for larger version

Name:	o3EgBpG.png
Views:	1
Size:	128.3 KB
ID:	1116614

              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.

              Comment


                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:

                Code:
                auto Isolate = NewObject<UJavascriptIsolate>();
                auto Context = Isolate->CreateContext();
                
                JavascriptContext = Context;
                
                Context->Expose("Root", this);
                Context->Expose("GWorld", GetWorld());
                Context->Expose("GEngine", GEngine);
                2) 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.

                [MENTION=33973]nako_sung[/MENTION], feel free to correct me if I'm following the wrong trail or giving bad advice here.

                Comment


                  [MENTION=157359]Flashback[/MENTION], 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.

                  Comment


                    Originally posted by nako_sung View Post
                    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)
                    If that doesn't break a compatibility with your future updates, sure =)

                    Originally posted by nako_sung View Post
                    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.
                    [MENTION=33973]nako_sung[/MENTION] If MyBlueprintFuncLib is decleared in C++, it's picked up automatically. If it's created as a blueprint in Content Browser, it isn't.

                    Click image for larger version

Name:	1.png
Views:	2
Size:	46.5 KB
ID:	1116660

                    Click image for larger version

Name:	2.png
Views:	1
Size:	76.5 KB
ID:	1116661

                    Click image for larger version

Name:	3.png
Views:	1
Size:	13.7 KB
ID:	1116662

                    Click image for larger version

Name:	4.png
Views:	1
Size:	36.0 KB
ID:	1116663

                    Comment


                      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?
                      Last edited by Apoctwist; 10-15-2016, 12:08 PM.

                      Comment


                        Hey, since 2 day's im trying to run a js function emitted by an existing c++ actor.

                        I tried to create a c++ Actor with BlueprintImplementableEvent, i can use it in Blueprint.

                        Now, tried to create a subclass from that c++ Actor class and overwrite the function, no success.
                        Then i created a Blueprint that inherit from my c++ Actor, same not working yet.

                        I can see my function being called inside the blueprint, so i thought i could create a blueprint function and overwrite that to get the data inside unreal.js - no success either.

                        Should i use multicast delegate ? Can i implement these events in js ?

                        I'd love to see some workflow that allows to call a function in c++ and is being received in js via "me.on("cpp_event",() => ..."

                        Heres some JS code..


                        Code:
                                 class UdpClient extends Blueprint.Load('/Game/UDP_B').GeneratedClass {
                                     constructor(){
                                        super();
                                    }
                                ctor() {
                                    // Subobject initialization, property initialization
                                    this.bAlwaysRelevant = true
                                }
                                  // THIS IS NOT WORKING
                                MyFunc()
                                    console.log("INSIDE JS");
                                }
                                  // FUNCTION THAT WORKS INSIDE BLUEPRINT, UNFORTUNATLY NOT FIRED HERE 
                                MCEvent(actor) {
                                    console.log("****");
                                    return blax(actor);
                                    // return call_your_js_func(actor)
                                }
                                blax(a){
                                    console.log("**Y*Y*Y*Y*Y*Y*Y*");
                                 }
                                 }
                        
                                let MyActor_Cx = require('uclass')()(global,UdpClient)
                                var blax = new MyActor_Cx(GWorld,{X:1});

                        Comment


                          [MENTION=157359]Flashback[/MENTION], unreal.js grabs all accessible classes during initialization, so your BP func library should be visible (loaded) before you create a javascript component.
                          [MENTION=65998]Apoctwist[/MENTION], I have tested with my macbook (updated to recent os, but I don't remember its code name) but I had no problem with the marketplace version. Could you elaborate your problem?

                          Comment


                            Hi is Android supported? I get errors like when i try to launch on the device:

                            D:/UE4/UnrealEngine/Epic Games/4.13/Engine/Plugins/Marketplace/UnrealJS/ThirdParty/v8/lib/Android/ARMv7/libv8_base.a(code-stubs.o):code-stubs.cc:function std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios(): error: undefined reference to 'std::__1::ios_base::~ios_base()'



                            Sanjit

                            Comment


                              Originally posted by nako_sung View Post
                              [MENTION=157359]Flashback[/MENTION], unreal.js grabs all accessible classes during initialization, so your BP func library should be visible (loaded) before you create a javascript component.
                              [MENTION=65998]Apoctwist[/MENTION], I have tested with my macbook (updated to recent os, but I don't remember its code name) but I had no problem with the marketplace version. Could you elaborate your problem?
                              I get the following error on my system when I try to launch Unreal 4.13.1 with eh plugin installed

                              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.

                              That's when I install it directly from the marketplace. I'm on the latest version of El Capitan.

                              Comment


                                [MENTION=65998]Apoctwist[/MENTION] I just found published mac osx build has problem with loading dylib's. Until next release of unreal.js, you can hack with a workaround for this issue.

                                https://github.com/ncsoft/Unreal.js/issues/121

                                Comment

                                Working...
                                X