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
Related
I created a PowerShell azure Function App with the default/sample function in it.
On the function app 'overview' page I clicked the 'download app content' and downloaded the 'content and visual studio project' including the app settings.
I put the content into an empty folder on my dev computer and opened it with Visual Studio 2022.
Updated the .net.sdk.functions nuget package to 4.1.1 and set the target framework to 4.8
When I start the debugging the function loads and listens, but when I open the URL it throws an exception: "Unable to find type [HttpResponseContext]"
It looks like the 'using namespace System.Net' line in the powershell code doesn't work. (the code/debugging works on the same computer from VSCode, but I would prefer using VS2022)
Any help to make this work would be appreciated. Thank you in advance.
This is part of the .csproj file:
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
This is the code:
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]#{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
Scenario 1:
Created PowerShell Core 7.2 Versioned Azure Function Http Trigger in the Azure Portal and downloaded it from the Overview blade with the following [Download App Content > Content & VS Project - Include app settings in the download].
Scenario 2:
When we create the same project from VS Code locally, it is not creating any .csproj file and if it is published without .csproj to Azure Portal Function App, Azure is sending the .csproj file in its Content and Visual Studio Project option with the net461 as target framework.
Error:
<Message>Exception while executing function: Functions.HttpTrigger1 -> PowerShell script error -> Unable to find type [HttpResponseContext].</Message>
....
<StatusCode>InternalServerError</StatusCode>
According to Azure Functions PowerShell Official Doc, .NET Framework is not supported in the PowerShell Runtime, but Azure is sending the framework version to the .csproj file.
We raised the triage ticket to the Microsoft on this issue and follow the updates from this GitHub ticket.
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
I'm trying to make a build by command line for WSA and not succeeding. I've tried with another project to make it for a windows standalone version and it's working.
Here is the command line:
C:\Unity\Editor\Unity.exe" -nographics -batchmode -projectPath "path
to project" -logFile "path to the file" -executeMethod
BuildScript.BuildGame
The BuildGame method is like this:
public static void BuildGame() {
string[] scenes = new string[] { "path to scene one",
"path to scene two" };
BuildPipeline.BuildPlayer(scenes, "path to the build\\Build.sln", BuildTarget.WSAPlayer, BuildOptions.None);
}
The weird thing is that the log says the compilation was successful, but it's not generating anything.
Thanks for the help.
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.
I'm trying to use Powershell DSC's Package resource to install an exe... Perforce's P4V to be specific. Here's my code:
Configuration PerforceMachine
{
Node "SERVERNAME"
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "\\nas\share\p4vinst64.exe"
ProductId = ''
Arguments = "/S /V/qn" # args for silent mode
LogPath = "$env:ProgramData\p4v_install.log"
}
}
}
When running this, this is the error Powershell gives me:
PowerShell provider MSFT_PackageResource failed to execute Set-TargetResource functionality with error message: The return code 1619 was not expected. Configuration is likely not
correct
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
+ PSComputerName : SERVERNAME
According to documentation, return code 1619 means the MSI package couldn't be opened. However, when I manually log in to the machine and run "\\nas\share\p4vinst64.exe /S /V/qn", the install works flawlessly.
Does anyone know why this is failing? Alternately, can anyone tell me how to troubleshoot this? I pasted all the error information I got from the terminal, my log file (p4v_install.log) is a 0 byte file, and there are no events in the event viewer. I don't know how to troubleshoot it any further!
EDIT: I should note that I also tried using the File resource to copy the file locally, and then install it from there. Sadly, that met with the same result.
Daniel over at the Powershell.org forums was able to figure this out for me.
The P4V InstallShield setup wrapper puts the MSI file into wrong path if you execute as LocalSystem.
I’ve managed to develop a Configuration that works, see below. The key is the /b switch here which puts the MSI file into a defined location. I’ve added ALLUSERS=1 to get the shortcuts visible to all users and REBOOT=ReallySuppress to avoid a sudden restart (which will happen otherwise).
Configuration PerforceMachine
{
Package P4V
{
Ensure = "Present"
Name = "Perforce Visual Components"
Path = "C:\My\p4vinst64.exe"
ProductId = ''
Arguments = '/b"C:\Windows\Temp\PerforceClient" /S /V"/qn ALLUSERS=1 REBOOT=ReallySuppress"' # args for silent mode
}
}
Well, what happens here is that the package gets installed (not tested with p4vinst64.exe yet! So, not sure why it says pack cannot be opened as the error) but since you did not specify a ProductID value, the verification at the end of install fails. That is the error you are seeing. The Package resource is no good for installing .exe packages or even MSIs with no ProductID represented as a GUID.
You can use the WindowsProcess resource instead.