Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

Example code for how to connect C++ to JS

Open jeebs00 opened this issue 3 years ago • 2 comments

Is there an example or documentation that explains how to expose C++ class functions for the plugin to pickup in a JS file? I am wanting to define a C++ class that I can call functions on in JS, I currently have them defined as UFUNCTIONS(BlueprintCallable) in a UCLASS() that extends AActor, but they are not being exposed in ue.d.ts file and I can't find where/what will trigger that file to update.

Mostly looking for an example of how to connect a C++ to be able to call a JS file, preferably without a function main(), to run a defined function (so how do I setup and instantiate a FJavascriptFunction in C++), since I could use the execute to pass the wanted parameters.

jeebs00 avatar Jun 29 '21 20:06 jeebs00

You can use expose function on a UObject* and it will have its functions callable from Js. See https://github.com/ncsoft/Unreal.js-core/blob/00305fc2b958f7819b66f7e23178c61ab54dbb84/Source/V8/Public/JavascriptComponent.h#L87

Also in my experience any c++ class with public api in module once compiled is subclassable and callable from Js, but I might be mistaken.

getnamo avatar Jun 30 '21 01:06 getnamo

When exposed that way it becomes referenceable. Even with the class exposed as API and UClass defined with UFUNCTIONS and UPROPERTY it wasn't updating.

jeebs00 avatar Jun 30 '21 19:06 jeebs00