Is there a serious bug in UnityEvents? Losing references on event trigger.

On my current project, I’m experiencing some serious issues when using UnityEvents. The project was handed to me by a client to complete but it soon became apparent that there was an issue with the event system. Either that, or I am missing a step somewhere.

There have been several instances of an event screwing up a reference to a class or object. A reference is defined in the target class’ Awake function. But when the event then calls another function within that class, the reference is null. And yes, I have tested the Awake function to make sure that the reference isn’t null to begin with.

It’s as if the Event trigger is creating an entirely new instance of the class (which inherits from Monobehaviour) just to call that one function.

Anyone else have this problem? I’m using Unity 2017.3.0f3

No we don’t have problems like that ^^. Are you sure you call the even on the correct object? The issue you’re describing sounds like you actually call the method on a prefab and not on an instance in the scene. Try adding a debug log like this at the beginning on your event method:

Debug.Log("Called event XYZ on gameobject " +, gameObject);

Note the second parameter. It allows to pass a context object. If you now click once on the log message in the console it will “ping” / highlight the actual object. Make sure the object is actually in the scene and not a prefab in the project.

You only gave a rough description of your issue so it’s hard to give a clear answer. If you need further help you should show the relevant code (especially who’s calling your “event”) and maybe a screenshot of your setup. Keep in mind that when you single click on a reference in the inspector it will also ping the referenced object.