AmbiguousMatchException when trying to set a property

Forums 💬 NodeCanvas ⚙️ Support AmbiguousMatchException when trying to set a property

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16511
    voktu
    Participant

      Hi,

       

      I have a PlayerInput component (from the new input system package) and it defines a property ‘camera’. But it shadows the ‘camera’ property from ‘UnityEngine.Component’.

       

      So when looking for available properties to set, the reflection code fails.

      Here is a fix:

      In EditorUtils.ContextMenu.cs, ‘static GenericMenu Internal_GetMethodSelectionMenu’

      //get the actual property to check for ObsoleteAttribute
      if ( method.Name.StartsWith(“get_”) || method.Name.StartsWith(“set_”) )
      {
      var name = method.Name.Replace(“get_”, “”).Replace(“set_”, “”);
      var bindingFlags = BindingFlags.Instance | BindingFlags.Public;
      try
      {
      member = method.DeclaringType.GetProperty(name, bindingFlags);
      }
      catch (AmbiguousMatchException) { bindingFlags |= BindingFlags.DeclaredOnly; }
      member = member ?? method.DeclaringType.GetProperty(name, bindingFlags);
      }

      This code will try the previous search, but if an ambiguity occurs, it searches only for the provided type and not its ancestors.

      #16512
      Gavalakis
      Keymaster

        Hello,

        Thank you for letting me know. I will take a look at this as soon as I can 🙂

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.