babalae/better-genshin-impact · error · InvalidOperationException
未找到材料:{_materialName}
Error message
未找到材料:{_materialName} What it means
Thrown as InvalidOperationException by CraftMaterialTask.FindAndSelectMaterial when TryFindAndSelectMaterial returns false. The method iterates all grid pages, uses an ItemRecognizer model to match each icon, and requires a score >= 0.75 with an exact name match plus OCR detail confirmation. If no page yields a matching, confirmable material, the search exhausted without success.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Job/CraftMaterialTask.cs:317
return true;
}
catch (TimeoutException e)
{
_logger.LogWarning("选择材料筛选类型 {MaterialType} 超时:{Message}", materialType, e.Message);
return false;
}
}
/// <summary>
/// 查找并选中目标材料,失败时抛出异常。
/// </summary>
/// <returns>异步任务。</returns>
/// <exception cref="InvalidOperationException">未找到目标材料时抛出。</exception>
private async Task FindAndSelectMaterial()
{
if (!await TryFindAndSelectMaterial())
{
throw new InvalidOperationException($"未找到材料:{_materialName}");
}
}
/// <summary>
/// 在合成列表中用图标模型查找并选中目标材料。
/// </summary>
/// <returns>找到并选中目标材料时返回 true。</returns>
private async Task<bool> TryFindAndSelectMaterial()
{
using ItemRecognizer itemRecognizer = new();
GridScreen gridScreen = new(GridParams.Templates[GridScreenName.Crafting], _logger, _ct);
gridScreen.OnAfterTurnToNewPage += GridScreen.DrawItemsAfterTurnToNewPage;
gridScreen.OnBeforeScroll += () => VisionContext.Instance().DrawContent.ClearAll();
try
{
await foreach ((ImageRegion pageRegion, Rect itemRect) in gridScreen)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Confirm the target material is actually craftable and visible in the current filter category.
- Check that the correct materialType filter was selected before search.
- Verify the material name string matches the game's exact display name.
- If the icon model is outdated, update the ItemV2 recognition model assets.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the material is craftable and visible in the selected filter before search // (pre-check via item.csv or user confirmation)
Type guard
null
Try / catch
try { await task.Start(ct); }
catch (InvalidOperationException ex) when (ex.Message.Contains("未找到材料")) { /* check filter, material name, model version */ } Prevention
- Verify the material name exactly matches the game's display name.
- Ensure the correct filter category is selected and materials are available.
When it happens
Trigger: The target material _materialName does not appear in the current crafting list (not craftable, wrong filter selected, insufficient base materials so it's hidden). The icon recognition model score is consistently below 0.75. The OCR detail confirmation (ConfirmSelectedMaterial) fails even when the model matches.
Common situations: The player lacks the prerequisite base materials so the target does not show. The wrong material filter category was selected. The material name in the task does not match the game's localized display name. The icon model is outdated and fails to recognize newer item icons.
Related errors
- 材料名不能为空。
- 合成个数必须大于 0。
- 未找到材料 {_materialName} 的材料类型,请传入 materialType 或检查 item.csv。
- 请先打开合成界面。
- 未能选择材料筛选类型:{materialType}
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/7824ab1899721c32.
Report an issue: GitHub.