[RELEASED] Flathead = UE4 + Javascript

[FONT=Arial Black]Overview

The first thing I ran into as a problem within the technical side of developing on the unreal platform, years ago, was the compile times. UnrealScript was occasionally a hand full of seconds long, but on larger projects it would balloon tremendously. Now that we have graduated to UE4 compile times are still much longer than simply saving files out. I am a firm believer in the benefits of working with scripting languages being bound to platforms, and have undertaken linking V8 into UE4 here. I will be documenting the capabilities in the change log that follows.

Please send me questions or comments directly, as if we rely upon forum notifications things may get past me. I will likely have an alpha together for people to test in the next few days.

[FONT=Arial Black]Download | [FONT=arial black]Wiki[FONT=Arial Black] | [FONT=arial black]Trello[FONT=Arial Black]

Change Log[SIZE=4][SIZE=5][/SIZE][/SIZE]

Unreleased

  • Updated to V8 v.3.29.58

[FONT=Arial Black]
Alfa Romeo - 1.0.0 - 05/26/2014

  • Exposing of variables as properties and using accessors is now working
  • Most of the UE4 float/double math library is exposed.
  • Started exposing UObject basics.

RC1 - 03/29/2014

  • Repurposed as Plugin. It is now fully self contained.
  • Executing Raw JS code from any point after the module StartModule method is functional. The plugin loads before game modules do.
  • addEventListener, CustomEvent dispatchEvent are now defined.
  • Load method added to API.
  • V8 is linked into UE4 via a module
  • Added a game object, which has a function for each level of UE4 logging as well as a property for the version of the game, defined in a constant.
  • Added a v8 object, providing a property to query the version of the binding, incremented as the API evolves, and a property to query the version of v8 included in the binding.
  • Loading of scripts based in the modules Source/JS directory from the console as well as from module loading.
  • String Conversion between V8 and UE4.
  • Exposing static methods in the form of an object

[FONT=Arial Black]&tldr;

I have linked V8 JavaScript into UE4 and am tuning it to purr like a kitten.
You may download immediately.

http://i.imgur.com/EFzbI9Bl.png

This is cool! Nice work!

I’m curious, what could this integration be used for?

Cheers,
Jon

I have an old Beta build, but I have already bound it into my world generation routine and handled the actual algorithm and creating of entities in the world entirely in JS. Now that we have full source access it can be extended to provide a callback to any C/C++ static or member function that can then call into any other part of the world. Its actually quite flexible and the API is up to us. I actually handled the eventing logic in JS land, creating the objects and what not in JS instead of having to create and validate all of the objects needed in C++, and it works swimmingly.

The only thing I am not entirely comfortable with is how to handle is references to assets, but that will come in due time, probably via a JS constructor call or something.

Cheers =)

Great project, manipulation through JS could be very handy for those coming from that realm.

I think that’s about the way it will work out. JS has a tendency to get messy pretty quick, but i think with some diligence on my part I may be able to sort that out. Its very interesting to be working with the full version of JS and not the subset that is available in Unity. I think tonight or tomorrow I may have some more time to get something useful together for you guys to see things working.

For now, I am waiting on the update to UE4 and revising my code.

This is an amazing project Bob!

Great work and very creative thinking on your part!

I agree, this would be a great addition.

I’m really looking forward to V8 integration, I had hoped this would happen, as I’ve got quite a chunk of AI/procedural code written in JS. Also, I’m currently teaching my 10-year-old nephew to program in JavaScript (in minecraft), this could act as a nice stepping stone.

Good luck!

I just finished sorting out the linking and resource notes for a plugin and V8 is now a togglable plugin in the UE4 Editor Plugins menu.

Would be nice to create server side, hot reload scripting.

Consider for example UOX (Ultima Online Emulator):

Officially posting my interest in this. Still quite new to the engine, and blueprint seems nice, but I do think there is a place for a scripting language with access to the same behaviors.

Am curious what the API would be like. Unity implements a strange class system (using a made up keyword) that automatically inherits from MonoBehavior (their basic class which can overrid Update - their tick method). To dump a behavior on an object, they have you drag a reference to the source onto the object in world, which creates a monobehavior component.

In UE, we have a blueprint object, which has a parent, and can access components on itself or the level trigger events, and so on. In C++ land, you have the same thing, but add your components via code in the constructor, like so:



SphereTrigger = PCIP.CreateDefaultSubobject<USphereComponent>(this, "SphereTrigger");


I wonder if on the js side, you could inherit using prototype chains and something like util.inherits from node.
Docs: Util | Node.js v20.1.0 Documentation
Source: node-v0.x-archive/util.js at master · nodejs/node-v0.x-archive · GitHub - it ends up being some very small boilerplate for setting up prototype chains

Resulting in something like:


function MyActor() {
    UE4.AActor.call(this);

    PCIP.CreateDefaultSubcomponent(UE4.USphereComponent, this, "SphereComponent");
}

util.inherits(MyActor, UE4.AActor);


Basically, mimicking the C++ API. Maybe too difficult to get it to behave the same, but just a thought. Could also use decorators or some sort of API to expose variables to the defaults editor so that you could extend a js “class” – p.s., don’t tell any javascript programmer that I used the word class. They’d **** in their pants.

I could see this also being highly useful for prototyping as a middle-ground (and actually due to the planned features an addition to) Blueprints and pure C++. I’d definitely be interested in helping maintain it when you decide to open it up.

Keep up the good work.

Issues now on public Trello

I have moved the Hurdles to Trello. Hopefully that will give you all more visibility into what I am currently working on so things are clear.

I am broken up about whether to allow comments or not, but for now they are open. Please be patient and follow Notch’s advice.

You can now vote & comment on issues to help me better prioritize my tasks to meet your demands.

Current Goal: Define a set of BP nodes that would be useful.

To Be Included in initial Release

  1. Load & Execute JS by fileName
  2. Execute Raw JS from text field or variable
  3. Retrieve value of object

Pardon my ignorance on the subject, but if this is V8 running inside UE, then could we not also extend that to include running other things that run on top of V8 like node or mongo. Just the thought of having a node server that would be able to interact with UE on this level has my head spinning with ideas! :wink:

You wouldn’t run another app on top of this, really. Mongo has c bindings, and Node does as well. This binding that I am putting together is really going to be focused on exposing, creating and interacting with game components.

The good news for you is that you can still interact across applications using TCP and UDP communication, as well as any sort of bindings you choose to spin up, like mongoDB managers or hell, you could put a web server together too if you so chose. There are a number of opportunities available to you. I can help you with at least getting a bearing if you are so inclined.

Alright folks. First RC is up. It is still very chaotic and you shouldn’t expect much in the way of API stability ATM. I am going to be around tomorrow, but you can and should try out the plugin. Drop it into your own project’s plugins directory and you will likely be able to see some fun and game frolicking around in your log files. As of now I am suggesting people build out their scripts by loading files at the beginning, hooking any events they plan to tie into at the initialization phase and firing events from their C++ at a later time.

The next release will be more useful, as I will be showing off how to expose objects, adding in the Execute method that will execute any arbitrary JS code anywhere in the code of your module.

Enjoy. Let me know what you think I can do better.

help! I’m having problem during installation. :frowning:

The should be unzipped at

MyGameModule/Plugins/V8Plugin/*

so that you get V8Plugin in that directory:

Exodus\Plugins\V8Plugin\V8Plugin.uplugin

I’ve put this way and gave this error.


C:\Users\User\Documents\Unreal Projects\ProjectX\Plugins\V8Plugin\V8Plugin.uplugin

Shoot me a message on IRC, AIM or Skype. Ill help you out. Maybe the instructions need to be expanded.