babalae/better-genshin-impact · error · InvalidOperationException

未找到目标角色 {CurrentTarget.Name}。

Error message

未找到目标角色 {CurrentTarget.Name}。

What it means

`FindAndClickAvatar` scrolls through the entire character grid and returns null when no card's recognized name matches the target above the similarity threshold (`MatchThreshold = 0.7`). The `FindAndClickAvatar` handler treats null as a hard failure because the target character could not be located at all.

Source

Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs:683

        }

        await Delay(500, _ct);
        _workflowState = CharacterDevelopmentState.FindAndClickAvatar;
        return StateHandlerResult.Success;
    }

    [StateHandler(CharacterDevelopmentState.FindAndClickAvatar, RetryTimeout = 30000, RetryInterval = 300, TransitionTimeout = 5000)]
    private async Task<StateHandlerResult> HandleFindAndClickAvatar(BvPage page)
    {
        var candidate = await CharacterSelectionHelper.FindAndClickAvatar(
            CurrentTarget,
            Recognizer,
            _assetScale,
            _logger,
            _ct);
        if (candidate == null)
        {
            throw new InvalidOperationException($"未找到目标角色 {CurrentTarget.Name}。");
        }

        CurrentResult.ElementType = candidate.ElementType;

        _workflowState = CharacterDevelopmentState.SelectedCharacter;
        return StateHandlerResult.Success;
    }

    [StateHandler(CharacterDevelopmentState.SelectedCharacter, RetryTimeout = 12000, RetryInterval = 300, TransitionTimeout = 5000)]
    private Task<StateHandlerResult> HandleSelectedCharacter(BvPage page)
    {
        Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE);
        _workflowState = CharacterDevelopmentState.SwitchCategory;
        return Task.FromResult(StateHandlerResult.Success);
    }

    [StateHandler(CharacterDevelopmentState.SwitchCategory, RetryTimeout = 12000, RetryInterval = 300, TransitionTimeout = 5000)]
    private Task<StateHandlerResult> HandleSwitchCategory(BvPage page)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Confirm the account owns the character and that the correct element/weapon filter is applied.
  2. Retrain or update the avatar recognition model/assets if scores are consistently low.
  3. Lower `MatchThreshold` only after verifying false positives are acceptable, or widen the grid ROI.
  4. Retry the whole task once (transient capture/OCR noise) before declaring the character missing.

Example fix

// before
var candidate = await FindAndClickAvatar(target, recognizer, scale, logger, ct);
if (candidate == null) throw new InvalidOperationException(...);

// after: retry once, then surface a clearer error
var candidate = await FindAndClickAvatar(target, recognizer, scale, logger, ct);
if (candidate == null)
    throw new InvalidOperationException($"未找到目标角色 {target.Name},请确认已拥有该角色且筛选条件正确。");
Defensive patterns

Strategy: retry

Validate before calling

// Before starting, sanity-check ownership is out of scope at runtime;
// instead validate filter types so the character isn't hidden:
var (el, wp) = GetFilterTypes(target, recognizer);
if (string.IsNullOrWhiteSpace(wp)) return; // skip rather than search doomed

Try / catch

try { await task.Start(ct); }
catch (InvalidOperationException ex) when (ex.Message.Contains("未找到目标角色"))
{ /* confirm ownership + correct filter; retry once */ }

Prevention

When it happens

Trigger: The character is not owned/unequipped; the avatar model misidentifies every card (low scores); the filter excluded the character (wrong element/weapon filter applied); the grid ROI or card detector produced no valid cards on any page.

Common situations: Asking for a character the account does not own; a filter mismatch hiding the character; model accuracy drop after a UI/art change; card detector thresholds too strict for the current resolution.

Related errors


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