Message System object reference exception
Posted: Thu Dec 03, 2020 6:03 am
Update: Please read 3rd comment first - the problem is not what it seemed to be.
I'm getting this error on two scripts:
The code in question is:
The class that's calling it inherits IMessageHandler. The receiver is set up like this:
I've tried to look into the source but I still can't figure out why it throws this exception. It also does seem to call the target method properly, despite the exception.
Also, side note: debugging sending generates double entries - from line 312 and 334 of MessageSystem.cs
I'm getting this error on two scripts:
Message System exception sending 'SETTLEMENT_SELECTED'/'' to Settlement Details (Mentor.PlaceDetailsUI): Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
PixelCrushers.MessageSystem:SendMessageWithTarget(Object, Object, String, String, Object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:342)
PixelCrushers.MessageSystem:SendMessage(Object, String, String, Object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:402)
Mentor.SettlementMarker:OnMouseDown() (at Assets/_Mentor/Scenes/Map/SettlementMarker.cs:62)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32) (at /Users/bokken/buildslave/unity/build/Modules/InputLegacy/MouseEvents.cs:161)
The code in question is:
Code: Select all
MessageSystem.SendMessage(this, "SETTLEMENT_SELECTED", "");
The class that's calling it inherits IMessageHandler. The receiver is set up like this:
Code: Select all
void OnEnable() {
MessageSystem.AddListener(this, "SETTLEMENT_SELECTED", string.Empty);
}
void OnDisable() {
MessageSystem.RemoveListener(this);
}
public void OnMessage(MessageArgs messageArgs) {
switch (messageArgs.message) {
case "SETTLEMENT_SELECTED":
UpdateDisplay((SettlementMarker)messageArgs.sender);
break;
default:
Debug.LogError("unknown message received: "+messageArgs.message);
break;
}
}
I've tried to look into the source but I still can't figure out why it throws this exception. It also does seem to call the target method properly, despite the exception.
Also, side note: debugging sending generates double entries - from line 312 and 334 of MessageSystem.cs