How Do I Ensure that --enable-unity-event-support is Set for iOS Builds?
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<Tween> { }
Here is the code that's getting called:
// setup the in-Tween
_inTween = gameObject.AddComponent<PositionTween>();
_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 <filename unknown>:0
at Controller+<ProcessLoadStep>c__Iterator9.MoveNext () [0x00000] in <filename unknown>: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<PositionTween>();
_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<PositionTween>();
_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.
You may want to try to debug the generated C++ code in Xcode in this case. That might lend some insight about what is causing the exception. You can find some details about how to do this on the blog post here:
http://blogs.unity3d.com/2015/05/20/il2cpp-internals-debugging-tips-for-generated-code/
We also have a demo about debugging generated code from Unite 2015 here:
One other note: you can see the command line that il2cpp.exe is called with in the Editor log file. Search it for "il2cpp".
I couldn't find anything in Editor.log regarding il2cpp. I was looking under ~/Library/Logs/Unity/Editor.log on OS X. I also looked through the other log files in that directory, but found nothing.
As far as debugging the internals, I wouldn't be able to submit the Xcode project. Our projects get built through Jenkins, which is all remotely handled by our HQ. I have limited control over tweaking the build process.
Although I get quite a few exceptions throughout my game at runtime, this is the only instance that appears to break something so far. It sounds like Unity's gone through quite a bit of IL2CPP maturity since 5.1.2, but I'm obligated to get this to work with 5.1.2. Are there any workarounds that I can do in C#? I've tried converting that UnityEvent into a C# delegate, but I get the same exception. To me, this suggests that this isn't a UnityEvent, but an event handler issue.
Could it be possible that "HandleTransitionInTweenFinished()" is somehow generating the NullReferenceException? I've verified that the GameObject and component of my handler method are both instantiated and attached about 500ms + 3 frames ahead of time lol.
Your answer
Follow this Question
Related Questions
Unity 5.2 ios IL2CPP build gives null reference exception 0 Answers
IL2CPP Build error Unity 5.3.1p4 0 Answers
[Not Answered] Fog not working iOS Build 2 Answers
ios build times slow for now reason 0 Answers
[SOLVED] In game narration system 1 Answer