Scripting Language extensions via plugins

I am following this thread since it was open. Looking forward to getting Lua support.

Can we expect Lua support to be a first order citizen, just like Blueprints?

I think it would be interesting to see Lua become a feature bullet for UE4, and possibly other lightweight languages that can be fit into this existing framework as well.

I have read through the LuaIntegration classes, and I wonder how hard it would be to create PythonIntegration, XIntegration, etc.
I think there needs to be a bit more work to it to have this feature more easily accessible from C++land, but the potential is endless!

We’re not currently planning to make any samples/games with it, but on the other hand it’s still not mature enough. I guess we’ll see how it goes. I am committed to supporting it though!

Yeah, there’s much potential and some very exciting things coming soon (better Blueprints integration and exposure to the editor)!

As for Python vs Lua - I never used Python, I did use Lua many years ago so that’s why I chose it for the proof-of-concept integration. I guess it wouldn’t be too hard to add Python too but I think we need to make Lua integration (and generally - the plugin itself) more solid and mature. Then adding new scripting language integration is only going to be a matter of a few working days.

Great work Robert! Here another +1 for “Lua first citizen” :wink:

I wouldn’t need the samples “just” for it to be feature complete and maintained.

C++ and Blueprints are great, but I’d really like a scripting language for UE4.

Thanks for the work on it!

Landed on 4.2! Great!

Hey everyone,

Quick update on the scripting integrations (so I guess that means Lua in particular :)):

You may be interested in two changes I checked in today (took a while to get this out, still WIP): Script Blueprint Classes and Script Property Propagation

So basically now you’re able to create Blueprint Classes from Lua. They will have all gloabal Lua variables exported as public properties (which you can set defaults for in a special version of BlueprintEditor) and all parameter-less global functions that start with “Event” exported as Blueprint-callable functions (works only for ScriptActors atm). Setting Lua properties from Blueprints works as expected, and the values are updated on the script side. The same goes for setting these properties on Lua side - they get propagated to the generated Blueprint class.

Also you can now chose between two base classes for your Lua Blueprints: ScriptActor and ScriptComponent. I’m pondering the possibility of specifying just about any Blueprintable base class and I’m definitely going to add it when I figure out the best way to do it. Cool thing is that you can basically use your ScriptComponent-derived components when designing ‘normal’ blueprints. Oh, and you should be able to specify the Lua generated Blueprints as base classes for normal Blueprints as well. It’s all Blueprint magic!

I’m planning to focus on user experience now. For now, Lua scripts are not automatically re-compiled and you need to double click on the class to open BP editor and click compile in there to do it. I also want to add the ability to have Lua scripts listed in generated projects in IDE (VS etc).

I think we are really close to production-ready phase with this now.

I’ve been working on a plugin that embeds Google V8 for javascript and even have coffeescript working as well. I’m watching this closely as I want to rewirte it to use your architecture.

I really like the sounds of this, especially if you can get any Blueprintable base class working. That’s a feature I really want to see.

Is it possible to have the script plugin available in the editor (or maybe that already works)? For coffescipt, I just load the coffeescript compiler (written in JS) into V8, then when I get a coffeescript file, I call the compiler from C++ and get back the compiled JS source, which I then give back to V8 as a script. The other option is to use the external coffeescript compiler and launch that from the editor.

If the script plugin is in the editor, it leads to a scriptable editor as well, a nice feature. I’d love to be able to write extentions to the editor in JS and test them live.

Would it be possible to add startup and shutdown scripts? I want a startup script that’s independent of blueprint that I can run after the engine is started, but before my game code, to load the JS libraries I need. A shutdown script would be nice as well to handle any cleanup.

Another feature I’d like to see is the ability to manage scripts independent of blueprint. For library files, I want to be able to include them in any build wihtout attaching them to a blueprint script. Maybe this already exist as well.

Thanks for the update!!

Yeah, sure. If you look at the three script plugins that are needed for the integration, you’ll notice that there’s a ScriptGenratorPlugin: UnrealHeaderTool extension); ScriptPlugin: runtime, this is where scripts are executed, it also loads in the editor and ScriptEditorPlugin: script compiler, Blueprint Compiler and a specialized version of BlueprintEditor, so you can basically add any other editors you wish there too.

Yes. It’s totally up to you if you want to add something like that. What my plugins provide is FScritpContextBase (in Lua: FLuaContext : public FScriptContextBase) which is a base class for scripting integrations, a place where implementation specific scripts live and all script-derived Blueprints use that to execute actual script code. You could also use it as standalone thing to execute scripts wherever you like.

That’s going to be the FScriptContextBase as well.

Ok, I found a way to support any class as base for scrip-generated classes. Now I can’t stop working on it and it’s Saturday! I blame you @jCoder!! :stuck_out_tongue:

Nice one !

:wink: I’m looking forward to what you come up with.

Great work! Are there plans to support UFunctions with TArray arguments? I updated to 4.3 wip and searched the generated .script code (for example) for:

But see no evidence of it…

Thanks!

I started working on TArray support in general some time ago but decided to get the script-generated classes functionality in place first. I’ll try to come back to it this month.

I’m very pleased to find this thread - it might be a lifesaver for me. When I got to this bit though:

then re-generate projects and compile the engine. UBT should automatically pick this up and enable Lua integration.

I got a bit stuck. Could you tell me what to do here?

Other than that, could you give me an example of…

In the default case where Lua is not enabled, SGP uses a generic script generator which exports simple wrapper functions around public class members.

I just need to get my toe in the door with regards to either of these (both of these) methods.

(Did you mention you had a blog? Where can I find it?)

Dan

  1. If you haven’t done so, you need to download the 4.3 preview engine source.

  2. Got to Lua: download and download the latest source

  3. Remove it from the archive (use 7zip or similar archive program) and put it in \Engine\Plugins\Script\ScriptPlugin\Source\ScriptPlugin\ in a folder called lua-5.2.3 If you do this right, in you should have a path at \Engine\Plugins\Script\ScriptPlugin\Source\ScriptPlugin\lua-5.2.3\src that contains the .c and .h source files for lua.

  4. Run the GenerateProject.bat script that’s in the root folder of your engine source.

  5. Rebuild the engine.

  6. You should now have an engine that has Lua built-in and you can add scripts to blueprint objects in the editor.

Excellent, looking forward to it. Thanks!

Hi jCoder - have you done anything interesting with this yet? I’m really trying to implement some kind of IP socket listener but my c++ sucks so much I’ll never get it done. Could it be done with this do you think?

I’m also trying to grab assets into arrays from paths but have had no luck with that either.

Dan.