Forums › 💬 NodeCanvas › ⚙️ Support › Generic Events with null values › Reply To: Generic Events with null values
Hello,
Thanks for bringing this to my attention. Null should definitely been possible to send (and compare with CheckEventValue).
Here are the final changes I’ve just made:
CheckEvent.cs
I’ve used reflection here so that assignable types work as well. It can be a bit slower, but also more flexible and convenient.
|
1 2 3 4 5 6 7 8 9 10 11 |
if (isActive && receivedEvent.name.ToUpper() == eventName.value.ToUpper()){ var eventType = receivedEvent.GetType(); if (eventType.RTIsGenericType()){ var valueType = eventType.RTGetGenericArguments().FirstOrDefault(); if (typeof(T).RTIsAssignableFrom(valueType)){ saveEventValue.value = (T)receivedEvent.value; } } |
CheckEventValue.cs
I don’t know what I was thinking in my previous code. It doesn’t make a lot of sense the way I did it before 🙂
I think I was trying to only catch events of the exact specified T type, but was not really convenient. This now handles assignable types as well as nulls of course.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public void OnCustomEvent(EventData receivedEvent){ if (isActive && receivedEvent.name.ToUpper() == eventName.value.ToUpper()){ var receivedValue = receivedEvent.value; if (object.Equals(receivedValue, value.value)){ #if UNITY_EDITOR if (NodeCanvas.Editor.NCPrefs.logEvents){ Logger.Log(string.Format("Event Received from ({0}): '{1}'", agent.gameObject.name, receivedEvent.name), "Event", this); } #endif YieldReturn(true); } } } |
Thank you!
