Build Unity Server under ubuntu via command line - unity3d

I created a very simple Unity Server, which uses a simple script (taken from here).
I tried to build it through the ubuntu bash with the following command:
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -buildLinux64Player /project/build/destination -quit
And it worked! It's able to create a working build. The problem is that the 3D windows is displayed as well. I don't want to interact with any game object.
Is there a way to create or run the executable without GUI?
As you can see I used "batchmode" and "nographics" flags which were supposed to prevent the user interface to appear.
Which sort of mistake I have done?
Thanks for your time.

As you can see I used "batchmode" and "nographics" flags which were supposed to prevent the user interface to appear.
yes and it didn't!
However, these two flags only apply to this instance of the UnityEditor which performs the build ... they do not apply to the actual resulting built application ;)
Usually you would go to the BuildSettings and enable
Server Build
Enable this checkbox to build the Player for server use and with no visual elements (headless) without the need for any command line options. When you enable this option, Unity builds managed scripts
with the UNITY_SERVER define, which means you can write server-specific code for your applications. You can also build to the Windows version as a console app so that stdin and stdout are accessible. Unity logs go to stdout by default.
under CommandLine Arguments you can find for how to trigger a scripted build via the console. Instead of using -buildXYZ you could use -executeMethod and within that method define the exact player and build settings you want before starting the build process
#if UNITY_EDITOR
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
class ScriptedBuilds
{
// Invoked via command line only
static void PerformHeadlessLinuxBuild()
{
// As a fallback use <project root>/BUILD as output path
var buildPath = Path.Combine(Application.dataPath, "BUILD");
// read in command line arguments e.g. add "-buildPath some/Path" if you want a different output path
var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i] == "-buildPath")
{
buildPath = args[i + 1];
}
}
// if the output folder doesn't exist create it now
if (!Directory.Exists(buildPath))
{
Directory.CreateDirectory(buildPath);
}
BuildPipeline.BuildPlayer(
// Simply use the scenes from the build settings
// see https://docs.unity3d.com/ScriptReference/EditorBuildSettings-scenes.html
EditorBuildSettings.scenes,
// pass on the output folder
buildPath,
// Build for Linux 64 bit
BuildTarget.StandaloneLinux64,
// Use Headless mode
// see https://docs.unity3d.com/ScriptReference/BuildOptions.EnableHeadlessMode.html
// and make the build fail for any error
// see https://docs.unity3d.com/ScriptReference/BuildOptions.StrictMode.html
BuildOptions.EnableHeadlessMode | BuildOptions.StrictMode
);
}
}
#endif
and then e.g.
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -executeMethod ScriptedBuilds.PerformHeadlessLinuxBuild -quit
or with a custom build output path
~/Unity/Hub/Editor/2019.4.30f1/Editor/Unity -batchmode -nographics -logfile stdout.log -projectPath /path/to/the/project -buildPath path/to/build/destination -executeMethod ScriptedBuilds.PerformHeadlessLinuxBuild -quit

Maybe you could try to add the #define UNITY_SERVER directive to the top of your script. This will enable the server build and disable visual elements see 'Server Build' option in the 'Platform list' table

Related

Cannot build Unity WebGL project from script

I have a problem with building Unity Project on WebGL target. This only appeares when I'm trying to build from script. When I build it from Unity project builds fine.
I think it can also be important, I'm running this methot from powershell script
PS Script:
$unityPath = "C:\Program Files\Unity\Editor\Unity.exe"
$unityParameters = "-batchmode -projectPath `"$($repo)\`" -username USERNAME -password PASS -executeMethod `"BuildScript.PerformBuild`""
$buildProcess = Start-Process -FilePath $unityPath -ArgumentList $unityParameters -Wait -PassThru
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Reporting;
public class BuildScript
{
public static void PerformBuild()
{
var projectName = "scene_1";
Debug.Log("### BUILDING ###");
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
var report = BuildPipeline.BuildPlayer(
new[] {$"Assets/Scenes/{projectName}.unity"},
$"Build/Win/{projectName}.exe",
BuildTarget.WebGL,
BuildOptions.None);
Debug.Log("### DONE ###");
Debug.Log(report);
EditorApplication.Exit(1);
}
}
Error I get in report:
Switching to WebGL:WebGLSupport is disabled
...
DisplayProgressNotification: Build Failed Error building player
Error building player because build target was unsupported
Please check if you have WebGL support installed at eg: C:\Program Files\Unity\2020.1.5f1\Editor\Data\PlaybackEngines\WebGLSupport
This error Switching to WebGL:WebGLSupport is disabled says that WebGLSupport is probably missing from you Unity installation.
Please double check that you are using the same installation of Unity in the script and in the Editor. You can check your path in UnityHub via Show in Explorer option

Can run yarn command from one Power Shell window, but not another. What could possibly explain the difference?

SUCCESS
I start PowerShell from the File explorer: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. I change directory to where I want to run the yarn command. I run yarn build which starts the script rollup --config --environment NODE_ENV:production. The application builds successfully.
FAIL
I start PowerShell from the start menu: C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk. This shortcut targets the executable above: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe. I change directory to where I want to run the yarn command. I run yarn build. The build errors.
src/renderer/renderer.tsx → app/build...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src\renderer\renderer.tsx (6:9)
4:
5: document.addEventListener("DOMContentLoaded", () =>
6: render(<App />, document.getElementById("root"))
^
7: );
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
at error (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:217:30)
at Module.error (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15145:16)
at tryParse (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15034:23)
at Module.setSource (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:15436:30)
at ModuleLoader.addModuleSource (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:17434:20)
at ModuleLoader.fetchModule (C:\Users\Me\Dev\graphics\svgconverter\node_modules\rollup\dist\shared\rollup.js:17495:9)
at async Promise.all (index 0)
at async Promise.all (index 0)
error Command failed with exit code 1.
LOOKING FOR DIFFERENCES
I have checked the file properties of the shortcut. It does not open the target as administrator. The owner is EUR/{Me}. System, Me and Administrators have all permissions checked except for special permissions. I think this is should not lead to any difference in behavior from starting PowerShell without using this shortcut?
I have printed the environment variables on both shells using dir env: | Format-Table -Wrap and they are completely equal.
So now I am scratching my head. What could possibly explain the difference?

run part of code as root

I have a package which runs uses Gtk and written in vala.A dialog box or a gui opens after selecting a file.I want this dialog box or gui to run as root so as to open and read the files which don't open with normal users.I have this code
static void open_file(string filename) {
selected_file = filename;
stdout.printf(selected_file);
new ProgressWindow(selected_file, {});
}
I want to run ProgressWindow to run as root.Is it possible?
No. To run as root, it must be in a separate process and you must run that process using pkexec via PolicyKit. Here's a tutorial on PolicyKit in Vala.

How to execute an InDesign extendscript from command line?

I need to execute a .jsx script for InDesign from command line (Windows).
For Illustrator, it works easily with the following command:
"C:\Program Files\Adobe\Adobe Illustrator CS6 (64 Bit)\Support Files\Contents\Windows\Illustrator.exe" "...\myscript.jsx"
Both applications Illustrator and ExtendScript Toolkit CS6 open then the script is automatically launched.
When I try the same for InDesign, it doesn't work (InDesign says 'Unable to open myscript.jsx ...').
I also tried to launch ExtendScript Toolkit from command line as below:
"C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\ExtendScript Toolkit.exe" "...\myscript.jsx"
The result is ExtendScript Toolkit application is opened with the script loaded, but nothing is executed.
Does anyone know how to launch the script? Is there a -run or -cmd argument to add?
For me on Osx it works like this:
/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOS/ExtendScript\ Toolkit -run test.jsx
On Windows it should be:
"\path\to\ExtendScript Toolkit.exe" -run test.jsx
content of test.jsx:
//#target indesign
alert(app.name);
It needs the -run flag. When using -cmd it still executes the script but from ESTK. The //#target indesign gets ignored. With the -run the script gets passed to InDesign. Unfortunately the ESTK brings up a dialogue that warns to execute scripts from untrusted sources.
a solution of yours could be to call a visualbasic script from command line. That VB would then call the indesign jsx file based on having referenced teh indesign application itself. Kind of tricky but should definitively work.
If you are trying to execute using node, these are the best two ways I have found to execute Indesign scripts.
Version Agnostic
Credit rendertom inside his vscode/atom plugins.
const outputFilePath = path.resolve(os.homedir(), 'Documents', 'Adobe Scripts', 'myscript.js');
const hostCommand = {
darwin: {
command: 'osascript',
args: [
'-e',
`tell application id "com.adobe.indesign" to do script "${outputFilePath}" language javascript`
],
options: {}
},
win32: {
command: 'powershell',
args: [
'-command',
`"$app = new-object -comobject InDesign.Application; $app.DoScript('${outputFilePath}', 1246973031)"`
],
options: {shell: true} // Windows requires a shell
}
};
if (typeof hostCommand[process.platform] == 'undefined') {
throw new Error('This platform is not supported');
}
const {command, args, options} = hostCommand[process.platform];
const p = spawn(command, args, options);
I don't have Windows at hand to actually test it but I would start by looking at those links:
Run VBS in command line : http://ss64.com/vb/cscript.html
Run InDesign in VB:https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjj9_3JoPXMAhVI1BoKHUKMBT8QFggfMAA&url=https%3A%2F%2Fwww.adobe.com%2Fcontent%2Fdam%2FAdobe%2Fen%2Fdevnet%2Findesign%2Fsdk%2Fcs6%2Fscripting%2FInDesign_ScriptingGuide_VB.pdf&usg=AFQjCNFP8M8i3xrOqLp0zw3BGcNpnyhEXQ&sig2=pfFYnsgxXDpCf1A573JTDQ&bvm=bv.122676328,d.d2s
Look at the DoScript method for calling a JSX script.
myInDesign.DoScript myJavaScript,
Without ExtendScript Toolkit and on a Mac, you can use AppleScript or JavaScript for Automation (JXA).
This is how it's done in the jasminejsx library to execute jasmine specs in ExtendScript.
osascript -l "JavaScript" -e "var app = new Application('com.adobe.indesign'); app.doScript('$EXTENDSCRIPT', {language: 'javascript'});" &
See code here.

AssetBundle Unity on Server

I would like to ask if anyone create Assetbundle in Unity on cloud? I would like to generate the AssetBundle dynamically on cloud and the client app will download it accordingly.
Could you let me know your idea? Is there any cloud service for hosting Unity ?
The accepted answer is spot on but there are slight changes as Unity5.6 now supports every other feature in the free version too. I've been working on a similar project that required building asset bundles dynamically. I'll post my code snippet for the same so that the process of identifying this gets simpler for everyone else in future.
But before that, there are some limitations for this process that you may need to consider. Building asset bundles dynamically on cloud requires (Command line) batchmode which runs Unity on commandline (Unity should be installed to build bundles). This asset building process works only on Windows and OSX (No Linux). The command to invoke Unity in batch mode is given below and has to be executed from Unity executable's location,
this command creates an empty project,
Unity -batchmode -quit -createProject <path/to/create a project>
After creating a project, you can save a script to build assets in the Assets/Editor folder, I have a written a script to automate the process of building assetbundle for all assets in the Assets/Models folder.
//BuildAssets.cs
using System.Collections;
using System.Collections.Generic;
public class BuildAssets : UnityEngine.MonoBehaviour
{
static void BuildAssetBundle()
{
int i = 0;
string log = "log.txt";
string[] assetN;
int N_Files;
UnityEditor.AssetBundleBuild[] AssetMap = new UnityEditor.AssetBundleBuild[2];
AssetMap[0].assetBundleName = "res";
// Adding to path /Models
string path = UnityEngine.Application.dataPath + "/Models";
//log
System.IO.File.AppendAllText(log, System.DateTime.Now.ToString() + "\n\n");
System.IO.File.AppendAllText(log, path + "\n");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] files = dir.GetFiles();
// Number of files in "/Models" folder
N_Files = files.Length;
//log
System.IO.File.AppendAllText(log, "Num assets: "+N_Files + " \n");
assetN = new string[N_Files];
foreach (System.IO.FileInfo file in files)
{
if (file.Exists)
{
if (!file.Extension.Equals(".meta"))
{
assetN[i] = "Assets/Resources/" + file.Name;
System.IO.File.AppendAllText(log, assetN[i] + " \n");
i += 1;
}
}
}
AssetMap[0].assetNames = assetN;
UnityEditor.BuildPipeline.BuildAssetBundles("Assets/AssetBundles", AssetMap, UnityEditor.BuildAssetBundleOptions.None, UnityEditor.BuildTarget.Android);
System.IO.File.AppendAllText(log, "\t----X----\n"); //log
}
}
This is the command for building the asset bundle through command line.
Unity -batchmode -quit -projectPath path/to/UnityProjects/Projectname -executeMethod BuildAssets.BuildAssetBundle -logFile <Log file location>
I've tested this and it works for our project.
AssetBundles require unity pro to build. There is a command line batch mode that you can use to build your asset bundles automaticly and host it on virtualy any host (a simple HTTP get).
Remember that you might not need asset bundles (or unity pro) - you can easily download textures and audio from the web using the WWW class. For textures you can use png, jpeg and tiff, for audio wav, ogg (only desktop and webplayer), mp3 (only mobile). Mesh loading should be also possible but that will require additional tools.