Small PSA - breaking change in Advanced CSharp Messenger in Unity 5.2

Hi all

Just in case this costs anyone else a wasted afternoon, I noticed after updating Unity to 5.2 that I started seeing some strange behavior in my game. I tracked it down to a breaking change in Advanced C# Messenger.

When you load a new scene, the messenger system has an event setup for “OnLevelWasLoaded” which calls “.Clear()” and deletes all your listeners. The change is that previously this ran before Awake, which has since been fixed in 5.2 and now runs after. That means if you setup all your listeners - like I do - in the Awake function, when you change levels the messenger will run out of order and accidentally delete your messages after setting them all up. The solution is to just comment out line 305 from Messenger.cs and call .Clear() manually.

It was confusing to track down because it only occurred when restarting my scene (which is just a single screen game), which led me on a bit of a wild goose chase thinking I was missing a static variable somewhere or not unloading a resource.

Hope that helps someone.

1 Like

What would this system be used for that couldn’t be accomplished with Unity Events?

Mostly just personal preference - Advanced C# messenger was around long before the Unity Events system so I’ve just naturally used it in most of my projects. I just prefer it as it has a lot less plumbing involved to throw some broadcasts around.