Simple JavaScript Scripting interpreter embedded in BluePrint


First of all, this might be in the wrong section, and might be a better fit for either the c++ section or the General Discussion section. So if a moderator feels that it belongs somewhere else, then please move it for me.

When I first started using UE4, I didn’t expect to like or use Blueprints that much, coming from a programming background. However I have really started liking it and found myself using it quite a lot. One problem with it though, is that some things can become very verbose and difficult to follow back. So as a proof of concept I have embedded a simple javascript interpreter into a Actor. This allows the user to add blueprint nodes that define and execute a javascript script.

It currently is at a very early stage of development and has a number of issues and will need a lot of work for it to become really useful. However I have already found it useful for making Math expressions a lot more compact and the blueprints containing them, easier to follow.

Some of the issues are:

  • As each script (section) is defined as a string, the blueprint editor only seems to allow a single line to be used for each string/script. So I found myself having to write the scripts in notepad and then copy and paste them across.
  • Currently very few Unreal engine functions are exposed to the scripts. As I said, so far I am mainly using them for Math expressions.
  • As the interpreter is embedded in a Actor class, it can only be used in Actors that subclass that class. Really I should put it in a component and then any Actor should be able to add the scripting component.
  • Will having a scripting interpreter that can be used in Blueprint just confuse people?

Having said all that, if there is interest in this, I will upload the c++ files here or on the wiki, so people can play around with it.

To try to show how it works a bit better, here is a screen shot of a blueprint that uses scripts to move the Actor’s location. Once when play begins, and then every time a key is pressed. In this simple example, just using the normal blueprint nodes would most likely be a lot better. However it might help to show what I’m talking about a bit better:

Or if we wanted to cut down the number of nodes, we combine the get and set variable nodes into the main script nodes, and also use a script print command to print the debug info to the screen:

This is actually pretty cool!
If there were a better editing window (Rather than the single line of doom) This could really be useful. I’d like to see some performance tests compared to native BP graphs.

The single line edit is really a problem. I haven’t looked too deeply into what it would take to allow multiple lines, but at some point I do plan to work on it.
Currently I’ve been working on making it work as a component, rather that being built into a Actor. I’ve also added support for a custom composite Node type. So that if a user adds a node of that type to a blueprint, they will be able to define the function template (parameters and return type) in the details window, and then pins for those parameter are automatically added to the node. So it works in a very similar way to the Math Expression plugin.

What if you’d provide a .js file name instead of the script. Or name of an element within some XML file which would contain the Javascript functions you need. It would be a little bit of an overhead to implement it, but it would be way more convenient in the end.
Could you please share the sources along with a licence for your code? I’d really love to take a look at it and perhaps tweak it to fit my needs if possible.

Sorry I didn’t realize anyone had added another comment.

Using .js files or nodes in a xml file should be perfectly possible and not take much extra work. However I really wanted to be able to edit the scripts in the editor, as you aren’t really going to write long scripts with this thing, so having to deal with external files would I think really take away some of it’s usefulness.

So with the aim of allowing editing to be done in the editor, I have been working on adding a edit box to the Details panel for the node. I have now reached a point where that basically “works”, but needs quite a bit more work done. One problem is that the Slate MultiLineEditableText widget, doesn’t actually work as it was never finished before the Unreal developers had to move onto higher priorities (according to an answer on the answerhub). So I have done some work to get the basic functions working in that. However due to dependencies, it would be a lot of work to move that widget’s code out of the Slate module, and my code is no where near ready for being submitted to be included into the main Engine/Editor’s code.

Actually it is easier to include a video to show my progress so far, than trying to describe how I have things working:

As for sharing the source, I do/did plan to make the source freely available. However at the moment, as I said I have had to make some changes in the core slate module and without those changes the rest of my code wouldn’t even compile at the moment. I do hope to work out a way around this, or better still hope that the MultilineEditableText widget is finished soon.

OMG man where is the download link !?!?!?!!?

Very interesting… That got me thinking maybe you could expand or make a separate one that works with say Python or LUA. This can be crazy powerful if used correctly.

Sounds like an excellent concept. In general I’d love to see scripting languages available in Unreal4. I am very interested in those source files. Please let me know if a download ever becomes available.

  • Joe

Semi-official support for Lua
A Javascript V8 plugin
A game-specific language called SkookumScript

I haven’t really done anything with this in months. So at the moment I have no plans to update it for the current version or release it. If you want scripting, then it is most likely best to check out the Lua plugin that Epic have wrote as a example of writing a scripting plugin. Link is in Veovis Muad’dib’s post.