You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Linux EC2上Unity批量构建报错:多实例冲突求助

问题描述

在AWS Linux EC2实例上安装Unity 2021.3.15f1,执行批处理构建命令时,明明只调用一次却报错:

"It looks like another Unity instance is running with this project open. Multiple Unity instances cannot open the same project."

已确认无Unity进程运行,重启EC2实例后问题依旧。以下是相关信息:

执行命令

xvfb-run /home/ec2-user/Editor/Unity -batchmode -nographics -projectPath /repo/VR-Survival/ -quit -logfile ~/editor.log -serial [my serial number] -username pawelmalysz@xxx.com -password my_password

完整日志(脱敏)

[ec2-user@ip-xxxx ~]$ cat editor.log
Unity Editor version:    2021.3.15f1 (e8e88683f834)
Branch:                  2021.3/staging
Build type:              Release
Batch mode:              YES
System name:             Linux
Distro version:          #1 SMP PREEMPT_DYNAMIC Tue Aug  1 20:47:25 UTC 2023
Kernel version:          6.1.41-63.114.amzn2023.x86_64
Architecture:            x86_64
Available memory:        15779 MB
User pawelmalysz@xxxx.com logged in successfully
[LicensingClient] Channel doesn't exist: "LicenseClient-ec2-user"
[Licensing::Module] Successfully launched the LicensingClient (PId: 2200)
No usable version of libssl was found
[LicensingClient] Channel doesn't exist: "LicenseClient-ec2-user"
[Licensing::Module] Timed-out after 60.00s, waiting for channel: "LicenseClient-ec2-user"
IPC channel to LicensingClient doesn't exist; falling back to Legacy licensing

LICENSE SYSTEM [202391 9:1:38] Next license update check is after 2023-08-19T08:54:23


LICENSE SYSTEM [202391 9:1:38] Current license is already valid and activated. Skipping license activation process (Provided username/password will be ignored).
Pro License: YES
Initialize udev device monitor.
[Package Manager] Server::Start -- Port 42797 was selected

COMMAND LINE ARGUMENTS:
/home/ec2-user/Editor/Unity
-batchmode
-nographics
-projectPath
/repo/VR-Survival/
-quit
-logfile
/home/ec2-user/editor.log
-serial
(hidden)
-username
pawelmalysz@xxxx.com
-password
(hidden)
-executeMethod
/repo/VR-Survival/Assets/Editor/Scripts/BuildScript.cs
Successfully changed project path to: /repo/VR-Survival/
/repo/VR-Survival
It looks like another Unity instance is running with this project open.

Multiple Unity instances cannot open the same project.

Project: /repo/VR-Survival
Fatal Error! It looks like another Unity instance is running with this project open.

Multiple Unity instances cannot open the same project.

Project: /repo/VR-Survival

构建脚本

using UnityEditor;

public class BuildScript
{
    public static void BuildLinux()
    {
        string[] scenes = { "Assets/Scenes/SplashSceen", "Assets/Scenes/MainMenu", "Assets/Scenes/Oregano", "Assets/Scenes/OtherScene" };
        string buildPath = "/home/ec2-user/SNBuild";
        Console.Log("TEST TEST");
        Debug.Log("TEST 2 Test 2");
        BuildReport buildReport = BuildPipeline.BuildPlayer(scenes, buildPath, BuildTarget.StandaloneLinux64, BuildOptions.None);

        if (buildReport.summary.result == BuildResult.Succeeded)
        {
            UnityEngine.Debug.Log("Build completed successfully.");
        }
        else
        {
            UnityEngine.Debug.LogError("Build failed. Error: " + buildReport.summary);
        }
    }
}
排查方向与解决办法
  • 清理Unity项目锁定文件
    Unity会在项目目录生成锁定文件防止多实例冲突,异常退出时这些文件可能残留。执行以下命令删除:

    rm -rf /repo/VR-Survival/Library/UnityLockfile
    rm -rf /repo/VR-Survival/temp/*
    rm -rf /repo/VR-Survival/obj/*
    
  • 修正-executeMethod参数错误
    日志显示命令中-executeMethod后填写的是脚本文件路径,这不符合要求。正确写法应为类名.静态方法名,即修改为:

    xvfb-run /home/ec2-user/Editor/Unity -batchmode -nographics -projectPath /repo/VR-Survival -quit -logfile ~/editor.log -serial [my serial number] -username pawelmalysz@xxx.com -password my_password -executeMethod BuildScript.BuildLinux
    

    注:确保脚本放在Assets/Editor目录下,Unity才能识别到该编辑器脚本。

  • 检查并修复项目目录权限
    确保ec2-user对项目目录拥有完整读写权限,执行:

    chown -R ec2-user:ec2-user /repo/VR-Survival/
    chmod -R 755 /repo/VR-Survival/
    
  • 清理License相关残留进程
    日志中LicensingClient出现超时问题,可能有残留进程。检查并杀掉相关进程:

    ps aux | grep LicensingClient
    kill -9 [进程ID]
    
  • 优化xvfb-run执行参数
    尝试指定独立的显示环境,避免可能的资源冲突:

    xvfb-run -a -s "-screen 0 1024x768x24" /home/ec2-user/Editor/Unity ...
    

    -a参数会自动分配可用的显示号,避免固定显示号的冲突。

  • 统一项目路径格式
    命令中-projectPath末尾的斜杠可能导致Unity路径识别异常,去掉末尾斜杠,改为/repo/VR-Survival。


内容的提问来源于stack exchange,提问作者Wolfik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 18:35:18