Announcement

Collapse
No announcement yet.

Node.js

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

    [PLUGIN] Node.js

    Hey Devs,
    I made a new experimental open source (MIT) plugin that embeds Node.js scripts as an actor component. Currently super early, but usable so wanted to share. Will likely have some bugs this early on, if you find any, post to https://github.com/getnamo/nodejs-ue4/issues.

    You can now write any node.js script and use npm modules to solve problems. The node instance is fully embedded, no external installation required.


    Main repository and documentation:
    https://github.com/getnamo/nodejs-ue4

    Latest release:
    https://github.com/getnamo/nodejs-ue4/releases


    Basic how-to

    e.g. a simple math function using the npm package ipc-event-emitter to listen and reply with events

    Code:
    //myscript.js - Let's connect our function via IPC
    
    //One liner include
    const ipc = require('ipc-event-emitter').default(process);
    
    const euclidean = (a, b) =>{
        return ((a ** 2) + (b ** 2)) ** 0.5;
    }
    
    //Listen to 'myevent' event
    ipc.on('myevent', (vars) => {
        let c = euclidean(vars.x, vars.y);
        console.log('Got a request (a^2+b^2)^0.5: ' + c);
    
        //emit result back as a 'result' event
        ipc.emit('result', c);
    });
    
    console.log('started');
    And on the blueprint side, add a node component



    set your script



    and bind to the event you used in your script and you can call your script function to e.g. get the Pythagorean distance of two floats


    The scripts run on background threads and will not block the game thread. Messaging does callback on game thread so bound events are safe to use as usual.

    That example is obviously just bare bones and not particularly useful, but you can change your script to use any NPM module (https://www.npmjs.com/) which has tons and tons of cool solutions to common programming problems.

    See this list for some ideas: https://github.com/getnamo/nodejs-ue...you-do-with-it


    Isn't this just unreal.js?

    Unreal.js is much much cooler and definitely better suited if you want to control unreal engine with javascript. This plugin instead focuses on bringing support for node.js API and full npm compatibility. You can probably use both together if you like.


    Limitations

    Win64 only for current builds.
    Last edited by getnamo; 07-20-2019, 01:05 AM.
    Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

    #2
    NPM auto-resolving and live-reloading scripts is now supported.

    Below is a novelty example testing the bandwidth of real-time communications, seems like you can easily do real-time and you'd need more than 20k messages/sec to impact the game thread without optimizations.

    Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

    Comment


      #3
      Originally posted by getnamo View Post
      NPM auto-resolving and live-reloading scripts is now supported.

      Below is a novelty example testing the bandwidth of real-time communications, seems like you can easily do real-time and you'd need more than 20k messages/sec to impact the game thread without optimizations.

      Hi, very good plugin.
      but to solve the following error, when loading dependencies (ipc-event-emitter) I had to copy the entire Plugins/Content/Scripts directory to my [ProjectRoot]/Content/Scripts.
      Is this correct? I thought I only had to indicate in Plugins/Content/Scripts/package.json the dependency to load.

      Click image for larger version

Name:	1.png
Views:	232
Size:	103.4 KB
ID:	1678439

      Click image for larger version

Name:	2.png
Views:	232
Size:	73.3 KB
ID:	1678440
      Attached Files

      Comment


        #4
        Originally posted by Helghast View Post

        Hi, very good plugin.
        but to solve the following error, when loading dependencies (ipc-event-emitter) I had to copy the entire Plugins/Content/Scripts directory to my [ProjectRoot]/Content/Scripts.
        Is this correct? I thought I only had to indicate in Plugins/Content/Scripts/package.json the dependency to load.

        ...
        Your initial thought is correct, the copying shouldn't be necessary. Just did a test, but it appears it has memory for the last executable path and the old node instance doesn't close always. After using the task manager to kill the stray node.js server and re-running the main script (either by restarting project or by running with bStopMainScriptOnNoListeners = true and exiting session) and then re-running again, the main script initializes correctly and will remain functioning as long as you don't move the folder. At that point it will pull the correct dependency folder instead of a different old path.

        Opened two new issues regarding these bugs here:
        https://github.com/getnamo/nodejs-ue4/issues/8 and https://github.com/getnamo/nodejs-ue4/issues/9

        Hopefully this silly workaround can be fixed with something proper.
        Last edited by getnamo; 10-31-2019, 12:37 PM.
        Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

        Comment


          #5


          Originally posted by Helghast View Post

          Hi, very good plugin.
          but to solve the following error, when loading dependencies (ipc-event-emitter) I had to copy the entire Plugins/Content/Scripts directory to my [ProjectRoot]/Content/Scripts.
          Is this correct? I thought I only had to indicate in Plugins/Content/Scripts/package.json the dependency to load.


          Originally posted by getnamo View Post

          You're initial thought is correct, the copying shouldn't be necessary. Just did a test, but it appears it has memory for the last executable path and the old node instance doesn't close always. After using the task manager to kill the stray node.js server and re-running the main script (either by restarting project or by running with bStopMainScriptOnNoListeners = true and exiting session) and then re-running again, the main script initializes correctly and will remain functioning as long as you don't move the folder. At that point it will pull the correct dependency folder instead of a different old path.

          Opened two new issues regarding these bugs here:
          https://github.com/getnamo/nodejs-ue4/issues/8 and https://github.com/getnamo/nodejs-ue4/issues/9

          Hopefully this silly workaround can be fixed with something proper.
          Made some small changes which should fix the lack of node instance stop on exit (issue 9). Not sure if issue 8 has been fixed though. Made a simple test project release with the updated plugin here: https://github.com/getnamo/nodejs-ue...ases/tag/0.4.2 Check out the NodeJSExampleProject-v0.4.2.7z release which should be a drag and droppable project with two maps, one for simple.js and another for adder.js. Adder.js should test the auto-resolve dependencies. Let me know if that version works for you.

          Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

          Comment


            #6
            Originally posted by getnamo View Post
            Made some small changes which should fix the lack of node instance stop on exit (issue 9). Not sure if issue 8 has been fixed though. Made a simple test project release with the updated plugin here: https://github.com/getnamo/nodejs-ue...ases/tag/0.4.2 Check out the NodeJSExampleProject-v0.4.2.7z release which should be a drag and droppable project with two maps, one for simple.js and another for adder.js. Adder.js should test the auto-resolve dependencies. Let me know if that version works for you.
            Only by playing AdderTestMap, the process imports the necessary modules and creates the node_modules folder.
            But the following error appears, even killing the nodejs processes created.:

            Code:
            LogBlueprintUserMessages: Late PlayInEditor Detection: Level '/Game/AdderTestMap.AdderTestMap:PersistentLevel' has LevelScriptBlueprint '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap' with GeneratedClass '/Game/AdderTestMap.AdderTestMap_C' with ClassGeneratedBy '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap'
            LogTemp: Error: Script Error: internal/modules/cjs/loader.js:638throw err;
                ^
            Error: Cannot find module 'ipc-event-emitter'
                at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
                at Function.Module._load (internal/modules/cjs/loader.js:562:25)
                at Module.require (internal/modules/cjs/loader.js:690:17)at require (internal/modules/cjs/helpers.js:25:18)
                at Object.<anonymous> (E:\Unreal Engine Projects2\NodeJSExamples\Content\Scripts\adder.js:4:13)
                at Module._compile (internal/modules/cjs/loader.js:776:30)
                at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
                at Module.load (internal/modules/cjs/loader.js:653:32)
                at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
                at Function.Module._load (internal/modules/cjs/loader.js:585:3)
            LogTemp: package.json contains missing dependency ipc-event-emitter, auto-resolving.
            LogBlueprintUserMessages: Early EndPlayMap Detection: Level '/Game/AdderTestMap.AdderTestMap:PersistentLevel' has LevelScriptBlueprint '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap' with GeneratedClass '/Game/AdderTestMap.AdderTestMap_C' with ClassGeneratedBy '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap'
            LogSlate: Updating window title bar state: overlay mode, drag disabled, window buttons hidden, title bar hidden
            LogWorld: BeginTearingDown for /Game/UEDPIE_0_AdderTestMap
            LogTemp: Removed a listener, 0 listeners left
            LogWorld: UWorld::CleanupWorld for AdderTestMap, bSessionEnded=true, bCleanupResources=true
            LogPlayLevel: Display: Shutting down PIE online subsystems
            LogBlueprintUserMessages: Late EndPlayMap Detection: Level '/Game/AdderTestMap.AdderTestMap:PersistentLevel' has LevelScriptBlueprint '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap' with GeneratedClass '/Game/AdderTestMap.AdderTestMap_C' with ClassGeneratedBy '/Game/AdderTestMap.AdderTestMap:PersistentLevel.AdderTestMap'
            LogSlate: Updating window title bar state: overlay mode, drag disabled, window buttons hidden, title bar hidden
            LogTemp: Removed a listener, 0 listeners left
            LogUObjectHash: Compacting FUObjectHashTables data took   1.38ms
            LogPlayLevel: Display: Destroying online subsystem :Context_2
            LogEditorSessionSummary: EditorSessionSummary sent report. Type=Shutdown, SessionId={35876D41-41C0-AB42-F3A1-D5B3D2CAC09A}
            LogEditorSessionSummary: EditorSessionSummary sent report. Type=Shutdown, SessionId={9A010913-48C5-DF86-0F36-AB9C769B9159}
            LogEditorSessionSummary: EditorSessionSummary sent report. Type=Shutdown, SessionId={907725D8-45DA-CDA0-9484-9B85CCFDCD72}
            LogEditorSessionSummary: EditorSessionSummary sent report. Type=Shutdown, SessionId={6FAFF7A5-4F1A-DAEC-19D8-51A4D8621702}
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            LogDirectoryWatcher: A directory notification failed for 'E:/Unreal Engine Projects2/NodeJSExamples/Content/' because it was empty or there was a buffer overflow. Attemping another request...
            Click image for larger version

Name:	nodejs-error.PNG
Views:	276
Size:	94.5 KB
ID:	1679556
            Click image for larger version

Name:	process.PNG
Views:	223
Size:	7.0 KB
ID:	1679557
            Greetings.

            Comment


              #7
              The log looks correct for the first part, but then after the auto-resolve the script should run.

              For the adder example it should look something like this the first time (press F to send input again):




              You can try to endplay/begin play a few times after pressing F to see if you get the adding blueprint to print out the default 5.0 value result. The javascript server does quit every time for me too. Regardless, something still appears broken :/ TBC, might need to find other machines to test it on.
              Last edited by getnamo; 10-31-2019, 01:03 PM.
              Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

              Comment


                #8
                Originally posted by getnamo View Post
                The log looks correct for the first part, but then after the auto-resolve the script should run.

                For the adder example it should look something like this the first time (press F to send input again):




                You can try to endplay/begin play a few times after pressing F to see if you get the adding blueprint to print out the default 5.0 value result. The javascript server does quit every time for me too. Regardless, something still appears broken :/ TBC, might need to find other machines to test it on.
                Hi, the last update for (nodejs-ue4-0.4.2) and (socketio-client-v1.2.0-UE4.23) works fine and now also works in StandAloneGame, NewEditorWindow (PIE) and VRPreview.
                But when I pack the game, I don't get these plugins to be packed too and therefore my tools don't work. I have to specify in the *.uplugin that are installed:

                Code:
                "Installed": true,
                However it also throws the following error when launching the packaged game:

                Click image for larger version  Name:	Sin-título.png Views:	0 Size:	3.6 KB ID:	1686088

                Grettings
                Last edited by Helghast; 11-12-2019, 03:28 PM.

                Comment


                  #9
                  Originally posted by Helghast View Post

                  Hi, the last update for (nodejs-ue4-0.4.2) and (socketio-client-v1.2.0-UE4.23) works fine and now also works in StandAloneGame, NewEditorWindow (PIE) and VRPreview.
                  But when I pack the game, I don't get these plugins to be packed too and therefore my tools don't work. I have to specify in the *.uplugin that are installed:

                  Code:
                  "Installed": true,
                  However it also throws the following error when launching the packaged game:

                  Click image for larger version Name:	Sin-título.png Views:	0 Size:	3.6 KB ID:	1686088

                  Grettings
                  Great that the 0.4.2 update worked for you. Regarding packaging, I haven't had time to address it yet, issue is being tracked here: https://github.com/getnamo/nodejs-ue4/issues/6. Largely I assume we just need to copy the thirdparty folder to the packaged build in the right location and it will work. TBC
                  Plugins: GES - Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo

                  Comment


                    #10
                    Originally posted by getnamo View Post

                    Great that the 0.4.2 update worked for you. Regarding packaging, I haven't had time to address it yet, issue is being tracked here: https://github.com/getnamo/nodejs-ue4/issues/6. Largely I assume we just need to copy the thirdparty folder to the packaged build in the right location and it will work. TBC
                    I got the following error when packaging the project for Windows.
                    I hope you find it useful, and if there is any correction soon.
                    I am using binary ue4. Not the code version.

                     
                    Spoiler


                    If I deactivate that the plugins are installed then it cooks well. But then the plugins folder is not inside the cooked one.
                    Code:
                    "Installed": false,
                    Click image for larger version  Name:	Sin-título1.png Views:	0 Size:	14.5 KB ID:	1686431
                    If I manually copy the plugins folder, then it gives the following error.
                    Click image for larger version  Name:	Sin-título0.png Views:	0 Size:	9.4 KB ID:	1686432
                    Click image for larger version  Name:	Sin-título.png Views:	0 Size:	5.5 KB ID:	1686433

                    Greetings.
                    Attached Files
                    Last edited by Helghast; 11-13-2019, 05:52 AM.

                    Comment

                    Working...
                    X