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.
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?
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:
And of course, it goes away with a type cast. I thought I’d done something like this before but apparently not.