getnamo/NodeJs-Unreal

pass command line arguments to the node script

xmak opened this issue · 5 comments

xmak commented

How do I pass command line arguments to the node script I want to execute?

I tried entering it in the "Default Script Path" field of the node component, but it gives me a "Cannot find module" error:

LogTemp: Error: Script Error: internal/modules/cjs/loader.js:638throw err; ^ Error: Cannot find module 'C:\Users\Marko\Downloads\NodeJSExamples\Content\Scripts\simple.js --test-param=1' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25)at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)at startup (internal/bootstrap/node.js:283:19)at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I don't believe commandline arguments are currently supported. It is expected to communicate with your script via ipc-event-emitter, see https://github.com/getnamo/nodejs-ue4#a-basic-adder for an example.

Adding commandline arguments would make a good enhancement though and shouldn't be too hard to add in theory. The related entry points would be https://github.com/getnamo/nodejs-ue4/blob/master/Source/CommandLine/Private/NodeCmd.cpp#L332, https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/nodeWrapper.js#L104, and https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L9. Looks like chopping up your scriptPath/name into args at https://github.com/getnamo/nodejs-ue4/blob/master/Content/Scripts/scriptHandler.js#L16 would probably do it.

xmak commented
xmak commented

Btw, when compiling the plugin, I get the following errors:

Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(5): fatal error C1083: Cannot open include file: 'PreWindowsApi.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(6): fatal error C1083: Cannot open include file: 'AllowWindowsPlatformTypes.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(18): fatal error C1083: Cannot open include file: 'HideWindowsPlatformTypes.h': No such file or directory
Plugins/nodejs-ue4/Source/CommandLine/Private/NodeCmd.cpp(19): fatal error C1083: Cannot open include file: 'PostWindowsApi.h': No such file or directory

This is easily fixed by appending "Windows/" to the include files in NodeCmd.cpp, should I correct this as well?

Those are fairly standard 4.24 compile bugs (they changed include precision), and for sure I'll merge anything that helps improve the plugin :)

xmak commented

I've made the quickfix, created pull request.

Btw, when I was testing the fix, I had to close Unreal Editor and open it again for changes in scriptHandler.js to be applied to the project. Is there a faster way to test it?