- Home /
Build from script
Forgive me if this has already been asked but i tried to search for anything on building or automatic building and found nothing on the subject.
What commands/classes do I need to use in order to get a script to build the current(or any really) project? The reason for this would be to use the command line options to be able to build a project without loading unity for example if I used blender to make changes to some of the models.
Answer by jashan · Dec 23, 2009 at 06:50 PM
BuildPipeline is your friend - that class provides a couple of methods to create builds from the editor ;-)
To use this from the command line, see Command line arguments. In particular, you'll be interested in: batchmode (no popup window), quit (quit Unity after work is done), projectPath (open a specific project), and executeMethod (this will be your method using BuildPipeline to create your build).
Thank you, this is exactly the type of thing I was looking for. Sadly I won't be able to use it until I get pro. Still worth knowing though!
Ah, sorry about that - I wasn't aware this was a pro-only feature. I guess I'll add that as tag (I think that's quite a relevant "tag").
Answer by VidRunr · Jan 27, 2013 at 04:59 PM
You can do simple builds from the command-line without Pro.
Here's little batch script I wrote for Windows. USERPROFILE is like *NIX HOME environment variable. To see the value on your system:
echo %USERPROFILE%
I realize it is not very generic at this point. It currently resides in a single Unity project.
I did notice some stability issues with Unity 3D 3.5+ when attempting to run the build script while Unity GUI was open. When ready to build, I exit Unity GUI then run the build script.
@echo off
set PROJECT=-projectPath
set PROJECT_PATH="%USERPROFILE%\Documents\project\Unity\UGDE"
set WIN_PATH="%USERPROFILE%\Documents\project\Unity\UGDE\build\win32\island.exe"
set OSX_PATH="%USERPROFILE%\Documents\project\Unity\UGDE\build\osx\island.app"
@REM With Unity 4 we now have Linux
set LINUX_PATH="%USERPROFILE%\Documents\project\Unity\UGDE\build\linux\island.app"
set LINUX64_PATH="%USERPROFILE%\Documents\project\Unity\UGDE\build\linux64\island.app"
@REM Common options
set BATCH=-batchmode
set QUIT=-quit
@REM Builds:
set WIN=-buildWindowsPlayer %WIN_PATH%
set OSX=-buildOSXPlayer %OSX_PATH%
set LINUX=-buildLinux32Player %LINUX_PATH%
set LINUX64=-buildLinux64Player %LINUX64_PATH%
@REM Win32 build
echo Running Win Build for: %PROJECT_PATH%
echo "%PROGRAMFILES%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %WIN%
"%ProgramFiles(x86)%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %WIN%
@REM OSX build
echo Running OSX Build for: %PROJECT_PATH%
echo "%PROGRAMFILES%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %OSX%
"%ProgramFiles(x86)%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %OSX%
@REM Linux build
echo Running Linux Build for: %PROJECT_PATH%
echo "%PROGRAMFILES%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %LINUX%
"%ProgramFiles(x86)%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %LINUX%
@REM Linux 64-bit build
echo Running Linux Build for: %PROJECT_PATH%
echo "%PROGRAMFILES%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %LINUX64%
"%ProgramFiles(x86)%\Unity\Editor\Unity.exe" %BATCH% %QUIT% %PROJECT% %PROJECT_PATH% %LINUX64%
PAUSE
Answer by Hoten · Dec 22, 2014 at 07:45 AM
I adapted VidRunr's bash script for my own build process. Here is a excerpt from it that shows how to build a Unity project with Ruby. This solution is much more succinct - you can actually tell Unity.exe to build to more than one platform at a time.
print "Build name?\n> "
build_name = $stdin.gets.chomp
base_dir = Dir.pwd
$build_dir = build_dir = "#{base_dir}/builds/#{build_name}"
server_dir = "#{build_dir}/gridia-#{build_name}-server-standalone"
win32 = "-buildWindowsPlayer #{build_dir}/gridia-#{build_name}-win32/client.exe"
win64 = "-buildWindows64Player #{build_dir}/gridia-#{build_name}-win64/client.exe"
osx = "-buildOSXPlayer #{build_dir}/gridia-#{build_name}-osx/client.app"
linux32 = "-buildLinux32Player #{build_dir}/gridia-#{build_name}-linux32/client.app"
linux64 = "-buildLinux64Player #{build_dir}/gridia-#{build_name}-linux64/client.app"
puts 'building clients for each platform'
unity = '"%PROGRAMFILES%/Unity/Editor/Unity.exe"'
`#{unity} -batchmode -quit -projectPath #{base_dir}/Client #{win32} #{win64} #{osx} #{linux32} #{linux64}`
Of course, you'd have to tinker the destination/project paths to suit your project.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Dynamically loading scripts 4 Answers
Programmatically Exporting an Asset Package 4 Answers
Help with door animation 1 Answer