AmbiguousMatchException in Missing Methods check when a UnityEvent targets an overloaded method
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in Editor/Categories/MissingReferences/MissingReferencesScanner.cs at ScanUnityEventReferences, around line 257, and inspect how the UnityEvent target method is resolved. Confirm the Missing Methods scan completes for overloaded methods such as AudioSource.PlayOneShot and does not treat a valid persistent call as missing.
Written by the indexing model from the issue text.
Description
Summary
The Missing Methods check in the MissingReferences category throws System.Reflection.AmbiguousMatchException whenever a scanned asset contains a UnityEvent persistent call whose target method has multiple overloads on the target type.
Steps to reproduce
- In any project, wire a
UnityEventon any component toAudioSource.PlayOneShot(AudioClip)(e.g. a ButtononClickor an XR interactable event playing a UI/select sound). Save the prefab or scene.
- Open Unity Scanner and enable the <Missing> Methods check.
- Run the analysis.
The scan of the MissingReferences category fails with:
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.RuntimeType.GetMethodImplCommon (...)
at System.RuntimeType.GetMethodImpl (...)
at System.Type.GetMethod (System.String name, System.Reflection.BindingFlags bindingAttr)
at UnityScanner.Categories.MissingReferences.MissingReferencesScanner.ScanUnityEventReferences (...) MissingReferencesScanner.cs:262
at UnityScanner.Categories.MissingReferences.MissingReferencesScanner+<ScanAllAssets>d__0.MoveNext () MissingReferencesScanner.cs:156
at UnityScanner.Categories.MissingReferences.MissingReferencesCategory+<Scan>d__27.MoveNext () MissingReferencesCategory.cs:38
at UnityScanner.Core.Categories.UnityScannerOrchestrator+<RunCategory>d__16.MoveNext () UnityScannerOrchestrator.cs:114
Root cause
ScanUnityEventReferences verifies method existence with:
var method = resolvedType.GetMethod(methodName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
if (method == null)
refsData.MissingMethods.Add(new MissingMethodEntry(typeName, methodName, i));
The Type.GetMethod(string, BindingFlags) overload throws AmbiguousMatchException by design when more than one method with that name exists on the type. AudioSource.PlayOneShot has two overloads (PlayOneShot(AudioClip) and PlayOneShot(AudioClip, float)), so the call throws instead of returning a match.
https://learn.microsoft.com/en-us/dotnet/api/system.type.getmethod?view=net-10.0#exceptions
The exception is thrown from here
https://github.com/AlexeyPerov/Unity-Scanner/blob/4baafb0808fc758c45561c79a691c05bbe58c7c1/Editor/Categories/MissingReferences/MissingReferencesScanner.cs#L257
Thanks
- Dominant language
- C#
- Stars
- 6
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·