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: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense
Working...
X