babalae/better-genshin-impact · error · PartySetupFailedException

选择队伍失败,等待队伍切换超时!

Error message

选择队伍失败,等待队伍切换超时!

What it means

Thrown by SwitchPartyTask.ConfirmParty after clicking the party-confirm button when the party-selection UI ('PartyBtnDelete' element) remains visible. NewRetry.WaitForAction polls up to 10 times (default 1000ms interval) for the delete-button element to disappear; if it never does, the UI never closed and the party switch is considered failed. It is a PartySetupFailedException (a plain Exception subclass), indicating an automation-flow failure against the live game UI, not a programming error.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Job/SwitchPartyTask.cs:245

        // 未找到
        Logger.LogError("未找到队伍: {Name},返回主界面", partyName);
        Logger.LogInformation("如果找不到设定的队伍名,有可能是文字识别效果不佳,请尝试正则表达式");
        await _returnMainUiTask.Start(ct);
        return false;
    }

    private async Task ConfirmParty(ImageRegion page, CancellationToken ct, bool isInPartyViewUi = false)
    {
        var r1 = Bv.ClickWhiteConfirmButton(page, new Rect(0, page.Height / 4, page.Width / 4, page.Height - page.Height / 4));
        var partyChooseUiClosed = await NewRetry.WaitForAction(() =>
        {
            using var ra2 = CaptureToRectArea();
            return ra2.Find(ElementRecognition.Get("PartyBtnDelete", ra2)).IsEmpty();
        }, ct, 10);
        if (!partyChooseUiClosed)
        {
            throw new PartySetupFailedException("选择队伍失败,等待队伍切换超时!");
        }
        await Delay(200, ct);
        using var ra = CaptureToRectArea();
        var r2 = Bv.ClickWhiteConfirmButton(ra, new Rect(page.Width - page.Width / 4, page.Height / 4, page.Width / 4, page.Height - page.Height / 4));
        await Delay(500, ct);
        if (isInPartyViewUi) await _returnMainUiTask.Start(ct);
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Verify the game is on a supported version and the party UI looks as expected; close any overlaying dialogs before running.
  2. Confirm the capture resolution and _assetScale match the design assumptions so the confirm-button click lands correctly.
  3. Increase the retry count or delay passed to NewRetry.WaitForAction (currently 10 retries) if the close animation is slow.
  4. Re-capture/update the 'PartyBtnDelete' element template under Assets if a game update changed its appearance.
  5. Check logs for the '截图失败' warning — if captures are failing, fix the capture backend first.

Example fix

// before
var partyChooseUiClosed = await NewRetry.WaitForAction(() =>
{
    using var ra2 = CaptureToRectArea();
    return ra2.Find(ElementRecognition.Get("PartyBtnDelete", ra2)).IsEmpty();
}, ct, 10);

// after — give the close animation more time and log on each miss
var partyChooseUiClosed = await NewRetry.WaitForAction(() =>
{
    using var ra2 = CaptureToRectArea();
    var btn = ra2.Find(ElementRecognition.Get("PartyBtnDelete", ra2));
    if (!btn.IsEmpty()) Logger.LogWarning("队伍选择界面仍未关闭");
    return btn.IsEmpty();
}, ct, 20, 800);
Defensive patterns

Strategy: try-catch

Validate before calling

// Before switching party, confirm the game is in the party view and the confirm button region is on screen
using var region = CaptureToRectArea();
if (region.Find(ElementRecognition.Get("PartyBtnDelete", region)).IsEmpty())
{
    Logger.LogWarning("未处于队伍选择界面,跳过确认");
    return;
}

Try / catch

try
{
    await ConfirmParty(page, ct, isInPartyViewUi);
}
catch (PartySetupFailedException ex)
{
    Logger.LogError(ex, "队伍切换超时,尝试返回主界面");
    await _returnMainUiTask.Start(ct);
    throw; // or return false to signal caller
}

Prevention

When it happens

Trigger: Called from ConfirmParty after SelectParty finds the target party name and clicks it. WaitForAction repeatedly calls CaptureToRectArea() + ElementRecognition.Get("PartyBtnDelete", ra2).IsEmpty(). If the in-game confirm click missed (wrong coords), the game was lagging, the UI changed in a game update, or an unrelated dialog obscured the screen, the element stays visible for all 10 retries.

Common situations: Game version update moved/renamed the party-delete button template; the confirm-button click region Rect(0, height/4, width/4, ...) no longer overlaps the real button at the current resolution/scale; game running slowly so the UI-close animation exceeds the poll budget; another popup (e.g. network notice) is open; resolution or _assetScale mismatch.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/efbc309479d772f8. Report an issue: GitHub.