Giter Site home page Giter Site logo

uetorch's Introduction

UETorch

UETorch is an Unreal Engine 4 plugin that adds support for embedded Lua/Torch scripts in the game engine loop, and a set of Lua APIs for providing user input, taking screenshots and segmentation masks, controlling game state, running faster than real time, etc. Torch is an AI Research platform that is focused on deep learning. UETorch strongly leverages the sparsely documented ScriptPlugin plugin provided with Unreal Engine 4.

Some recent research done using the UETorch platform is detailed in this paper "Learning Physical Intuition of Block Towers by Example" where we explore the ability of deep feed-forward models to learn intuitive physics.

Requirements

See the Unreal Engine 4 Requirements. UETorch was developed for Linux; see Building Unreal Engine on Linux. Running on Mac and Windows is not currently supported, but should be relatively straightforward if you're willing to figure out the build process.

Installing UETorch

  1. Download and install torch from https://github.com/torch/torch-distro. When it's time to run install.sh or .bat, set the Lua version to 5.2:

Linux

TORCH_LUA_VERSION=LUA52 ./install.sh

Windows

set TORCH_LUA_VERSION=LUA52
./install.bat
  1. Set up an Epic Games account at https://github.com/EpicGames/Signup/, needed to clone the Unreal Engine repository from github. UETorch currently only works with the source distribution of UE4, not the binary download.
  2. Install all the Linux prerequisites mentioned at https://wiki.unrealengine.com/Building_On_Linux. In the case of Windows, skip this step.
sudo apt-get install build-essential mono-gmcs mono-xbuild mono-dmcs libmono-corlib4.0-cil \
libmono-system-data-datasetextensions4.0-cil libmono-system-web-extensions4.0-cil \
libmono-system-management4.0-cil libmono-system-xml-linq4.0-cil cmake dos2unix clang xdg-user-dirs
  1. Install UnrealEngine / UETorch

Linux

git clone https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine

# clone UETorch into the plugins directory
git clone https://github.com/facebook/UETorch.git Engine/Plugins/UETorch
# run the UETorch setup script
# this will update you to a specific revision on UnrealEngine-4.8, add some patches, and set up the Lua paths
Engine/Plugins/UETorch/Setup.sh

# grab some coffee, this will take a long time
./Setup.sh && ./GenerateProjectFiles.sh && make

Windows

git clone https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine

rem clone UETorch into the plugins directory
git clone https://github.com/facebook/UETorch.git Engine/Plugins/UETorch
rem run the UETorch setup script
rem this will update you to a specific revision on UnrealEngine-4.13, add some patches, and set up the Lua paths
Engine/Plugins/UETorch/Setup.bat

rem grab some coffee, this will take a long time
./Setup.bat && ./GenerateProjectFiles.bat

Since UE4.sln has been generated, build it with Visual Studio.

  1. Profit!

Getting Started with UETorch

  1. Source the uetorch_activate.sh script. You might want to add this to your .bashrc.

Linux

source Engine/Plugins/UETorch/uetorch_activate.sh

Windows

call Engine/Plugins/UETorch/uetorch_activate.bat
  1. Launch Unreal Editor

Linux

cd Engine/Binaries/Linux
./UE4Editor

Windows

cd Engine/Binaries/Win64
./UE4Editor
  1. Create a new 'First Person' project. Create a 'First Person' Project

  2. Lets add a TorchPlugin component to the player. In the 'World Outliner' panel, select 'FirstPersonCharacter', and then in the 'Details' panel, click 'Add Component' and select 'Torch Plugin' (you can use the typeahead). Add a Torch Plugin Component to FirstPersonCharacter

  3. Now we just need to tell the UETorch component which script to run. We'll use the example script in UETorch/Scripts/uetorch_example.lua. Just set the 'Main Module' field on the TorchPlugin to 'uetorch_example'. (If you sourced uetorch_activate.sh, then UETorch/Scripts should already be on your LUA_PATH). Set the 'Main Module' field to uetorch_example

  4. Press the 'Play' button. The player should move towards the cubes, based on the simple tick function inside uetorch_example.lua. Go take a look at that script now. You can exit the game by pressing the 'Esc' key. This script demos several different UETorch features:

  • locates the blocks via a segmentation mask, and moves the character towards them by simulating keyboard input.
  • takes a screenshot after 100 frames and saves it to ./uetorch_screenshot.jpg.
  • moves one of the blocks into the air via the uetorch.SetActorLocation function.
  1. You can call a Lua function from inside Unreal Engine's Blueprints scripting language. We'll add a routine to the 'level blueprint' that calls into Lua and starts the REPL when you press the 'H' key, which will allow you to run the Lua interpreter interactively inside a game. Open the level blueprint (from the Blueprints menu). Right click in the main window to add a new widget, uncheck 'Context Sensitive', and search for 'Call TorchFunction'. This widget just calls a Lua function with no input or output (only void -> void and string -> string widgets are provided; you can write your own as well). You can then drag your FirstPersonCharacter into the blueprint and hook it up as the target to the widget. Read the Blueprints documentation for more details. Here's what the final blueprint should look like The final blueprint
  2. The interactive Torch REPL won't work inside this editor process because it is a child process with no attached TTY. In the main Editor window, go to File->Open Project, check 'Always load last project on startup', and then close the window. Then restart UE4Editor, and it should directly load your Project.
  3. Now press 'Play' again, and press the 'H' key. The game should freeze and you will enter the Torch REPL inside of your terminal.

Full documentation

To learn how to develop Unreal Engine projects, see the Unreal Engine documentation at https://docs.unrealengine.com/latest/INT/.

In-line documentation for the APIs provided by UETorch can be found in uetorch.lua.

More coming soon.

Join the UETorch community

See the CONTRIBUTING file for how to help out.

License

UETorch is BSD-licensed. We also provide an additional patent grant.

uetorch's People

Contributors

adamlerer avatar edenton avatar flarnie avatar marioyc avatar soumith avatar suryabhupa avatar yhase7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uetorch's Issues

Function CaptureScreenshot crashes in UE4.10

I tried to install UETorch on UE4.10. Everything is fine except editor will crash once uetorch.Screen() is called(Signal 11 caught, probably access wrong memory address). Does it happen in your test?

Couldn't find lua.h relative to lua.

When executing the UETorch installation script ./Engine/Plugins/UETorch/Setup.sh I get this:

=== Setting up Lua... === 
Couldn't find lua.h relative to lua. Did you forget to install torch and run torch-activate?

I am on Ubuntu 16.04 and I have torch installed, activated and working properly. The lua command points to the runtime installed by the system (most likely not the one used by torch). Suggestions?

fatal error: 'lua.h'

I get this when trying to make UE4Editor. I have this file at ~/torch/exe/luajit-rocks/lua-5.2/src/lua.h.

Similar problem: torch plugin don't fire in packaged game

Hi,

I've looked at your discussion below. I have a similar problem that everything is correct but UETorch don't fire. Once I tried to intrigue the callTorchFunction, it shows LogScript:Warning: Accessed None 'TorchPlugin'. And I tried with add lua library folder but doesn't work. I wonder if it is the same issue reported before.

UE4 patch failed

I am on Ubuntu 14.04.3 LTS and I installed torch from the latest main branch. I am having problems with 'Engine/Plugins/UETorch/Setup.sh'. The error message is pasted below. I would appreciate any pointers

D Engine/Source/ThirdParty/zlib/zlib-1.2.5/build/zlib-1.2.5.tar.gz
Already on '4.8'
Your branch is up-to-date with 'origin/4.8'.
Checking dependencies (excluding Win32, Win64, Mac, HTML5, Android)...
Result: 0
=== Patching UE4 ===
error: patch failed: Engine/Source/Runtime/Engine/Classes/Engine/World.h:928
error: Engine/Source/Runtime/Engine/Classes/Engine/World.h: patch does not apply
error: patch failed: Engine/Source/Runtime/Engine/Private/Components/PrimitiveComponent.cpp:1425
error: Engine/Source/Runtime/Engine/Private/Components/PrimitiveComponent.cpp: patch does not apply
error: patch failed: Engine/Source/Runtime/Engine/Private/LevelTick.cpp:1112
error: Engine/Source/Runtime/Engine/Private/LevelTick.cpp: patch does not apply
error: patch failed: Engine/Source/Runtime/Engine/Private/World.cpp:123
error: Engine/Source/Runtime/Engine/Private/World.cpp: patch does not apply
error: patch failed: Engine/Source/Runtime/Linux/ALAudio/Private/ALAudioDevice.cpp:84
error: Engine/Source/Runtime/Linux/ALAudio/Private/ALAudioDevice.cpp: patch does not apply
error: patch failed: Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp:16
error: Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/ScriptPlugin.cpp:16
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/ScriptPlugin.cpp: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h:13
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h: patch does not apply
error: patch failed: Engine/Plugins/ScriptGeneratorPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp:97
error: Engine/Plugins/ScriptGeneratorPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp: patch does not apply
error: patch failed: Engine/Plugins/ScriptGeneratorPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs:48
error: Engine/Plugins/ScriptGeneratorPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs:29
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs: patch does not apply
=== Setting up Lua... ===

If the Viewport is null the editor crashes

This happens if for example you set a timer to call a function that uses UETorch every 0.1 seconds and at some point quit the game but a call to the function is still done.

undefined symbol: lua_newstate error when trying to add Torch Script Plugin

When I get to the step in the tutorial where we have to add in the Torch tutorial, but the following error happens and UnrealEngine simply exits:

[2016.04.27-02.48.57:724][ 0]LogContentStreaming: Texture pool size is 0.000000MB
[2016.04.27-02.48.57:880][ 0]LogContentStreaming: Texture pool size now 1000 MB
[2016.04.27-02.48.58:973][ 8]LogAssetRegistry: Asset discovery search completed in 20.9050 seconds
/home/surya/UnrealEngine/Engine/Binaries/Linux/UE4Editor: symbol lookup error: /home/surya/UnrealEngine/Engine/Plugins/UETorch/Binaries/Linux/../../../ScriptPlugin/Binaries/Linux/libUE4Editor-ScriptPlugin.so: undefined symbol: lua_newstate

The installation of UETorch went smoothly.

Building on Mac

Some notes on how to do this in case someone needs it:

  1. It is necessary to change the "liblua.so" in ScriptPlugin.Build.cs to "liblua.dylib"
  2. The line "ln -sfT $TORCH_BIN/.. install" fails on Mac but removing the "T" argument seems to do it as well
  3. It seems like the "RenderCore" and "Slate" references are missing in UETorch.Build.cs
  4. There are problems when building with the last version of Xcode because the clang versions are not compatible, Xcode 6.4 works ok.
  5. In uetorch_activate.sh it was necesary to change "$(readlink -f $sourced)" by just "$sourced" since readlink returns an empty string if the argument is not a symbolic link.

Using a more recent version of UE?

Hi,

I managed to compile UE4Editor, but it crashes when I launch it. The error I get is:

[2016.09.23-19.34.43:062][  0]LogGenericPlatformMisc: FPlatformMisc::RequestExit(1)
Assertion failed: Match(ShaderSource, '(') [File:/home/myrhev/dl/UnrealEngine/Engine/Source/Developer/ShaderFormatOpenGL/Private/OpenGLShaderCompiler.cpp] [Line: 1049] 

[2016.09.23-19.34.43:172][  0]LogLinux:Error: appError called: Assertion failed: Assertion failed: Match(ShaderSource, '(') [File:/home/myrhev/dl/UnrealEngine/Engine/Source/Developer/ShaderFormatOpenGL/Private/OpenGLShaderCompiler.cpp] [Line: 1049] 

The only thread I can find online about this issue is https://answers.unrealengine.com/questions/258959/ue4editor-linux-crash.html . And they suggest to update to version 4.9.

I understand people have managed to make it work with UE 4.10, but I can't find how. That would be awesome if someone who managed to use UE4.10 could write a quick howto, or just explain how they did it. Also, the pastie link in #19 is dead, which doesn't help.

Thank you!

Generating ProjectFiles is stuck

Once I set up UETorch before Unreal Engine set up, in the step ''./GenerateProjectFilesh":
it shows "+ mono Binaries/DotNET/UnrealBuildTool.exe -makefile -kdevelopfile -qmakefile -cmakefile
Using clang version '3.5.0' (string), 3 (major), 5 (minor), 0 (patch)" and got stuck. Do you have any ideas towards this.

alternative implementation of uetorch.SetResolution

Hi Adam,

First of all, thanks for the UETorch plugin that works very well! I'm working on the NaivePhysics project after @marioyc, using the 4.8 version for now.

I found a problem with the current implementation of the SetResolution function. Taking a screenshot just after a resolution change give a black image (but depth and masks are OK). Below is an alternative implementation that fixes the problem...

// implemented from https://wiki.unrealengine.com/Game_User_Settings
extern "C" bool SetResolution(int x, int y) {
  if(! GEngine)
    return false;

  UGameUserSettings* Settings = GEngine->GameUserSettings;
  if(! Settings)
    return false;

  Settings->RequestResolutionChange(x, y, EWindowMode::Type::Windowed, false);
  Settings->ConfirmVideoMode();
  return true;
}

Error while patching

Hi,

I am trying to install UETorch, but when I ran the Engine/Plugins/UETorch/Setup.sh command, I got the following error. I tried installing everything from scratch again, but I still got the same error. I am using Ubuntu 14.04.

=== Checking out the baseline UE4 commit... ===
M Engine/Plugins/ScriptPlugin/ScriptPlugin.uplugin
M Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp
M Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.cpp
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs
M Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp
Already on '4.13'
Your branch is up-to-date with 'origin/4.13'.
=== Patching UE4 ===
M Engine/Plugins/ScriptPlugin/ScriptPlugin.uplugin
M Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp
M Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.cpp
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h
M Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs
M Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp
Switched to branch '4.13-UETorch'
error: patch failed: Engine/Plugins/ScriptPlugin/ScriptPlugin.uplugin:10
error: Engine/Plugins/ScriptPlugin/ScriptPlugin.uplugin: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp:97
error: Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/Private/ScriptGeneratorPlugin.cpp: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs:46
error: Engine/Plugins/ScriptPlugin/Source/ScriptGeneratorPlugin/ScriptGeneratorPlugin.Build.cs: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.cpp:612
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.cpp: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h:13
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/Private/LuaIntegration.h: patch does not apply
error: patch failed: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs:10
error: Engine/Plugins/ScriptPlugin/Source/ScriptPlugin/ScriptPlugin.Build.cs: patch does not apply
error: patch failed: Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp:26
error: Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp: patch does not apply

Could you please help me fix this?

Torch scripts don't fire after packaging with Unreal

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.