Unity 5.5 UnityAction error CS0121. Is this a bug?

Unity 5.5 is not happy about member overloading using UnityAction arguments. The script works perfectly fine in Unity 5.4.3, but in 5.5.0 it generates the following error:

Assets/Test.cs(7,3): error CS0121: The call is ambiguous between the following methods or properties: Test.Map(UnityEngine.Events.UnityAction<float>)' and Test.Map(UnityEngine.Events.UnityAction)

Is this error intended by UT, or is it a bug in Unity 5.5?

Same problem for System.Action btw.

~ce

using UnityEngine;
using UnityEngine.Events;

public class Test : MonoBehaviour
{
   void Start(){
      Map( FloatMethod );
      Map( IntMethod );
   }

   void FloatMethod( float value ){
      Debug.Log( value );
   }

   void IntMethod (int value ){
      Debug.Log( value );
   }

   void Map( UnityAction<float> method ){
      method.Invoke( 0f );
   }

   void Map( UnityAction<int> method ){
      method.Invoke( 0 );
   }
}

Ooo, that’s nasty. There were some overload bugs in older versions of C# so I wouldn’t be surprised if this is a side-effect of living in the C# dark ages.

http://stackoverflow.com/a/8674811/152997

Thanks for your insight. Wow, if that is the case, it is really shit news. I have several scripts that break because of this. We may have to wait years for C# 5 to make it into Unity. It would be great to have someone from UT confirm this.

Meanwhile …

I wonder what would be the most graceful workaround?

As usual, StackOverflow has an explanation, and some solutions…
http://stackoverflow.com/questions/2057146/compiler-ambiguous-invocation-error-anonymous-method-and-method-group-with-fun

2 Likes

Well that’s interesting… implicit conversions. The clue is in the fact that only the float version is highlighted as ambiguous, since an int can be automatically cast to a float:

2880160--211388--1.jpg

And of course, it goes away with a type cast. I thought I’d done something like this before but apparently not.

void Start()
{
    Map((Action<float>)FloatMethod);
    Map(IntMethod);
}
2 Likes