Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Torch scripts don't fire after packaging with Unreal #5

Open
ericdanz opened this issue Mar 27, 2016 · 17 comments
Open

Torch scripts don't fire after packaging with Unreal #5

ericdanz opened this issue Mar 27, 2016 · 17 comments
Labels

Comments

@ericdanz
Copy link

I created a simple Torch script that just saved a screenshot, to test this out. It works great in the editor, but does not work at all if I package the game and run the resulting executable. I have checked the logs, it imports uetorch.lua and prints the initialization message when building.
When I run it, it looks correct, all the right (non-Torch) things are happening in the game, but the screenshots are not being saved.

I also tested this with the uetorch_example script and the basic first person project, with similar results - the scene is rendered well, but the character doesn't move forward and turn like he does in the editor.

@ericdanz
Copy link
Author

I found an error in the log that is related -
Found 1 script generator plugins. MainFrameActions: Packaging (Linux): mono: [2016.03.27-16.49.38:558][ 0]LogCompile: Unable to determine output directory for ScriptPlugin. Cannot export script glue with 'Lua Example Code Generator Plugin' MainFrameActions: Packaging (Linux): mono: [2016.03.27-16.49.38:558][ 0]LogCompile: Script generator 'Lua Example Code Generator Plugin' not supported for target: UnrealBuildTest

@adamlerer
Copy link
Contributor

Hi @ericdanz , sorry you're having trouble packaging your game. I'm not sure that this is what's causing your problem. Here's what's executed in the embedded Lua interpreter in UETorch to startup your script:

FString UTorchPluginComponent::MakeLuaInitString() {
  FString InitStr = "require 'uetorch';"                 // FIXME: use local uetorch package
                    "local _main = require '" + MainModule + "';"
                    "if type(_main)=='table' and _main.initialize then _main.initialize() end";
  return InitStr;
}

My first guess would be that your packaged game can't find uetorch.lua or .lua. Are you sure you've set the LUA_PATH environment variable correctly?

@ericdanz
Copy link
Author

Here's my LUA_PATH variable:

/home/eric/UnrealEngine/Engine/Plugins/UETorch/Scripts/?.lua;/home/eric/UnrealEngine/Engine/Plugins/UETorch/Scripts/?/init.lua;/home/eric/.luarocks/share/lua/5.2/?.lua;/home/eric/.luarocks/share/lua/5.2/?/init.lua;/home/eric/torch/install/share/lua/5.2/?.lua;/home/eric/torch/install/share/lua/5.2/?/init.lua;/home/eric/torch/install/lib/lua/5.2/?.lua;/home/eric/torch/install/lib/lua/5.2/?/init.lua;./?.lua

It includes both the scripts directory and the lua directory - but I think that would also effect the in-editor run right?

I'm recompiling it now to see if I can suss out any more clues - if this doesn't work I'll make a new project as a C++ project and see if I get different results (that fixed plugin issues with some people in the Unreal forums).

@adamlerer
Copy link
Contributor

I've found that your best bet is to look at not the compile logs but the logs at runtime. You can instrument the code (both on the C++ and Lua side) in UETorch with logging/print statements to see at what point it's failing. My guess is it's not finding Lua, or not finding the correct lua source files, or something like that. You could also run in gdb and add breakpoints inside UETorch, e.g. inside TorchPluginComponent.cpp in the OnRegister function.

@marioyc
Copy link
Contributor

marioyc commented Apr 4, 2016

I was looking at the build logs today because the packaging failed and getting this:

[2016.04.04-17.32.23:093][ 0]LogScriptPlugin:Warning: Cannot call Lua function (null): /home/mario/distro/install/share/lua/5.2/trepl/init.lua:384: module '<MainModule>' not found: no field package.preload['<MainModule>'] no file '/home/mario/UnrealEngine/Engine/Plugins/UETorch/Scripts/<MainModule>.lua' no file '/home/mario/UnrealEngine/Engine/Plugins/UETorch/Scripts/<MainModule>/init.lua' no file '/home/mario/UnrealEngine/Engine/Plugins/UETorch/Scripts/<MainModule>.lua' no file '/home/mario/UnrealEngine/Engine/Plugins/UETorch/Scripts/<MainModule>/init.lua' no file '/home/mario/.luarocks/share/lua/5.2/<MainModule>.lua' no file '/home/mario/.luarocks/share/lua/5.2/<MainModule>/init.lua' no file '/home/mario/distro/install/share/lua/5.2/<MainModule>.lua' no file '/home/mario/distro/install/share/lua/5.2/<MainModule>/init.lua' no file '/home/mario/distro/install/lib/lua/5.2/<MainModule>.lua' no file '/home/mario/distro/install/lib/lua/5.2/<MainModule>/init.lua' no file './<MainModule>.lua' no file '/home/mario/distro/install/lib/<MainModule>.so' no file '/home/mario/.luarocks/lib/lua/5.2/<MainModule>.so' no file '/home/mario/distro/install/lib/lua/5.2/<MainModule>.so' no file '/home/mario/distro/install/lib/lua/5.2/loadall.so' no file './<MainModule>.so'

the solution seems to be changing MainModule in TorchPluginComponent.cpp:

MainModule = TEXT("uetorch");

and the rebuild UETorch, maybe that works for this problem too.

@adamlerer
Copy link
Contributor

@marioyc the original code in TorchPluginComponent.cpp MainModule = TEXT("<MainModule>") is there because you are supposed to fill that in with your main module inside the Unreal Engine UI (see the Getting Started doc). Did you create a TorchPlugin component in the UI but forget to set the "Main Module" field?

If you just hardcode this to uetorch in C++, it will just load the uetorch library but not whatever script/code you want to run.

@marioyc
Copy link
Contributor

marioyc commented Apr 4, 2016

No, the Main Module field was filled, but I was still getting this at the moment of packaging.

@adamlerer
Copy link
Contributor

@ericdanz @marioyc I have reproduced the same problems you guys had. If you remove the assignment of MainModule in the constructor, it at least solves the compilation problem, but the TorchPluginComponent never fires inside the packaged game (in fact, UTorchPluginComponent::OnRegister() is never even called).

When I was doing development a while back, I was using ScriptPlugin directly, and packaging games did work.

I haven't figured it out, but some hypotheses:

@adamlerer
Copy link
Contributor

@marioyc
Copy link
Contributor

marioyc commented Apr 27, 2016

I tried changing the Build.cs file and add UETorch to PublicDependencyModuleNames as mentioned on the first link, however after packaging the game when I try to run it I get:

./UETorchTest: error while loading shared libraries: liblua.so: cannot open shared object file: No such file or directory

The same thing happened when adding only ScriptPlugin which is where liblua,so is being added (here). Any ideas about why it is not being found?

@adamlerer
Copy link
Contributor

When you package the game, do you get the following message:

Log.TraceVerbose("LUA Integration enabled: {0}", LuaInstallDirectory);

If so, what does it say LuaInstallDirectory is? Is it correct, i.e. does liblua.so live there?

@marioyc
Copy link
Contributor

marioyc commented Apr 28, 2016

I've tried setting the log level to verbose as described here in the DefaultEngine.ini file of the game but I am not seeing any of the LUA integration messages on the Cook.[number].txt log file.

@marioyc
Copy link
Contributor

marioyc commented Apr 28, 2016

It could be that I'm not setting the log level the right way, since I also tried adding liblua.so from the game's Build.cs too, but neither of the messages is appearing in the logs.

@marioyc
Copy link
Contributor

marioyc commented Apr 28, 2016

I was finally able to get the messages printed with Console.WriteLine and it's printing

  • /home/mario/UnrealEngine/Engine/Plugins/ScriptPlugin/Source/Lua/install for LuaInstallDirectory
  • /home/mario/UnrealEngine/Engine/Plugins/ScriptPlugin/Source/Lua/install/lib/liblua.so for LuaLib

in the UnrealBuildTools.[number].txt log which are the right paths.

@adamlerer
Copy link
Contributor

Can you try running the packaged game with LD_LIBRARY_PATH set? Like:

LD_LIBRARY_PATH=/home/mario/UnrealEngine/Engine/Plugins/ScriptPlugin/Source/Lua/install/lib ./myPackagedGame

@marioyc
Copy link
Contributor

marioyc commented May 2, 2016

Yes, now it is working.

@adamlerer
Copy link
Contributor

Awesome! I'm happy we finally figured it out.

To fix this for others, it would be best if UETorch packaged the .so into the packaged game itself and compile the game to include it in its library paths. If we can't figure it out then lets just add it to the docs and add an error message inside UETorch when it can't find liblua.so that says "set LD_LIBRARY_PATH to the folder containing liblua.so"

@adamlerer adamlerer added the bug label Nov 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants