UnityEvent issues with object reference (iOS)

I’m experiencing issues when invoking UnityEvent objects assigned in the editor. In my project where I use them, the Invoke call fails sometimes with a NullReferenceException (4.6b21, happened also in 4.6b20). It only happens on iOS, but not in the editor and not in a standalone build.

System.NullReferenceException: A null value was found where an object instance was required.
  at UnityEngine.Events.PersistentCall.GetObjectCall (UnityEngine.Object target, System.Reflection.MethodInfo method, UnityEngine.Events.ArgumentCache arguments) [0x00000] in <filename unknown>:0

full stacktrace

System.NullReferenceException: A null value was found where an object instance was required.
  at UnityEngine.Events.PersistentCall.GetObjectCall (UnityEngine.Object target, System.Reflection.MethodInfo method, UnityEngine.Events.ArgumentCache arguments) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
  at SubSceneEnd.End (EndingDefinition endDef) [0x0001e] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/SubSceneEnd.cs:68
  at SubSceneEnd.End (System.String endName) [0x0007c] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/SubSceneEnd.cs:48
  at UnityEngine.Events.InvokableCall`1[System.String].Invoke (System.Object[] args) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.CachedInvokableCall`1[System.String].Invoke (System.Object[] args) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
  at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <filename unknown>:0
  at OnAnimationEvent.AnimationEvent (System.String obj) [0x0001d] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/OnAnimationEvent.cs:31
  at at (wrapper delegate-invoke) System.Action`1<string>:invoke_void__this___string (string)
  at SpriteAnimationControllerBase.SendFrameEvent () [0x0006a] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Sprites/SpriteAnimationControllerBase.cs:141
  at SpriteAnimationControllerBase.SetAnimation (System.String animName) [0x00035] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Sprites/SpriteAnimationControllerBase.cs:59
  at SpriteAnimationControllerQueued.Step () [0x00061] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Sprites/SpriteAnimationControllerQueued.cs:59
  at InteractiveObject.OnFrameTick () [0x0003d] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Core/InteractiveObject.cs:192
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at at (wrapper delegate-invoke) System.Action:invoke_void__this__ ()
  at FrameTickManager.FrameTick () [0x00024] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Utilities/FrameTickManager.cs:69
  at FrameTickManager+<FrameTickLoop>c__Iterator13.MoveNext () [0x00031] in /Volumes/Data/Documents/Projects/Plug and Play/pnp.git/Assets/Scripts/Utilities/FrameTickManager.cs:40

The event is set to a function which receives a object reference set in the inspector as argument. The object is assigned and not null.

The failing invoke call is sent from here:

public class SubSceneEnd : MonoBehaviour {

    [System.Serializable]
    public class EndingDefinition
    {
        public string name;
        //...
        public UnityEvent beforeEnterState;
        public UnityEvent afterEnterState; // this one
    }

    //is called by another UnityEvent
    public void End(string endName)
    {
        // ..
        afterEnterState.Invoke();
    }

}

this the function assigned to the event in the inspector:
1815774--116105--Screen Shot 2014-10-20 at 18.29.23.png

public class CableSceneManager : MonoBehaviour
{
        // CableScene is a class derived from MonoBehaviour
    public void SetScene(CableScene sc)
    {
        // do stuff
    }
}

It works when the called function (SetScene in this case) takes an int as an argument, but not if it is an Object.

I tried to create a simplified bug report project, but I’m not able to reproduce it outside that project. Did anybody experience similar issues?

Hi, we don’t have a bug on this issue. Are you using code stripping? Could you try enabling / disabling this?

If you manage to find a nice repro I would love to have it.

With disabled code stripping it works. With “strip Byte code” it doesn’t. I’ll try again to make a repro.

Ok, made a repro project and submitted the bug (case number 641874).

Thank you.