Properly calling UFunction::Invoke() for a Custom Scripting Engine


I found out about the UClass::ProcessEvent function which does mostly what I need except for one thing: the standard approach seems to be to create a struct holding the arguments. Problem is that for this context we won’t know which data types are going to be needed and thus cannot generate a static struct suitable for all cases. Thus the new problem is how to generate struct-like memory ranges, which is harder than one might think…

Dear Community,

I’m currently working my way through the ScriptPlugin and Blueprint source code to understand how to get the max out of the UE4 Property System. Originally I was hoping it would be much easier. While working with class properties in fact is fairly simple, invoking any function unknown at compile time is a lot harder. I find this to be quite counterproductive when developing a custom scripting engine or embedding a third party scripting engine.

In fact I was embedding the SpiderMonkey JavaScript engine and had developed a layer of abstraction between SpiderMonkey and UE4. The last bit I need is a sort of proxy method to forward function calls from JavaScript to UE4 Natives. However I now find myself working tediously with FFrame’s directly.

I was hoping it was possible to simply pass in the arguments in a TArray<UProperty>*, but I was oh so wrong. While I’m still not quite sure how to iterate over the methods of a class, I now simply find a function by name if possible, then construct the FFrame of the function and invoke it. For those who don’t know: FFrame must be constructed with a void* to the raw bytes of the arguments to be passed in. I feel as if I were working with Assembler - in fact, it may even be easier to achieve this with inline assembler since documentation on this topic is extremely scarce and the exact opposite of verbose.

Of course most people will not need any of this as Blueprint scripting is powerful enough in itself. But I greatly prefer JavaScript over Lua and really want to script my games in this language.

So to maybe save me some time, if any Guru out there could help me out in this issue I’d be extremely grateful. All I’d need to know is how to properly invoke UFunction::Invoke().

Thank you in advance for any assistance!

P.S.: Of course I could create an API which would expose specific functions to JavaScript, but that approach would be rather limited. My current approach would allow us to do nearly anything we’d like to in JavaScript as if it were Blueprints. It would probably lack IntelliSense and search, but that’s always been an issue when working with such a volatile language like JavaScript. My ultimate goal is to create a scripting engine which would allow for a very simple first degree of moddability simply by using an interpreted language. Thus this entire topic might be useful for anybody