Hey all, I've been getting NullReferenceExceptions for my IL2CPP builds whenever I call AddListener() on my derived UnityEvent. Here is my UnityEvent derivative:
[Serializable]
public class TweenEvent : UnityEvent { }
Here is the code that's getting called:
// setup the in-Tween
_inTween = gameObject.AddComponent();
_inTween.TweenFinished.AddListener(HandleTransitionInTweenFinished); // exception occurs
_inTween.Curve = new AnimationCurve(EaseInKeyframes);
_inTween.Begin = new Vector3(TransitionDistance, 0.0f, 0.0f);
_inTween.End = Vector3.zero;
_inTween.Duration = TransitionDuration;
The NullReferenceException happens with AddListener(), but that's all the information I get. I've verified that _inTween and _inTween's TweenFinished property (TweenEvent) are not null using debug logs. I get no runtime exceptions or have any issues with my code in the editor or with builds on Android devices. Everything runs fine on iOS when I use Mono2x instead of IL2CPP. I need to use IL2CPP though.
I'm also using Unity 5.1.2f on OS X El Capitan. I'm not able to upgrade my version of Unity due to our internal framework's compatibility managed by another team.
Also, is there a way that I can verify that --enable-unity-event-support is being passed to il2cpp when making iOS builds from OS X?
UPDATE: I did a test with C# delegates instead of UnityEvents, and I got the same error. Here's the error I get in Xcode:
NullReferenceException: A null value was found where an object instance was required.
at Step.Setup (Controller controller, UnityEngine.RectTransform spawnTransform) [0x00000] in :0
at Controller+c__Iterator9.MoveNext () [0x00000] in :0
It still happens at the AddListener() line. Here's the complete Setup() method that I'm having trouble with:
public void Setup(Controller controller, RectTransform spawnTransform)
{
// get the RectTransform, and assign the Parent controller
RectTransform rectTransform = (RectTransform)transform;
Parent = controller;
if(Parent != null)
{
// setup the RectTransform
rectTransform.SetParent(spawnTransform);
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.one;
rectTransform.localScale = Vector3.one;
// setup the in-Tween
_inTween = gameObject.AddComponent();
_inTween.TweenFinished.AddListener(HandleTransitionInTweenFinished); // EXCEPTION
_inTween.Curve = new AnimationCurve(EaseInKeyframes);
_inTween.Begin = new Vector3(TransitionDistance, 0.0f, 0.0f);
_inTween.End = Vector3.zero;
_inTween.Duration = TransitionDuration;
// setup the out-Tween
_outTween = gameObject.AddComponent();
_outTween.TweenFinished.AddListener(HandleTransitionOutTweenFinished); // EXCEPTION
_outTween.Curve = new AnimationCurve(EaseInKeyframes);
_outTween.Begin = Vector3.zero;
_outTween.End = new Vector3(-TransitionDistance, 0.0f, 0.0f);
_outTween.Duration = TransitionDuration;
}
}
This suggests that my private HandleTransitionIn(Out)TweenFinished() methods are null, but how can that be? The GameObject and component instance are both created. I also get more NullReferenceExceptions through the runtime of my game on iOS/IL2CPP that never occurs on iOS/Mono or Android builds.
↧