Generic Events with null values

Forums 💬 NodeCanvas ⚙️ Support Generic Events with null values

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17235
    step
    Participant

      Hey everyone,

      I just stumbled upon a problem with generic Events in NodeCanvas. The issue is that I am able to send null as a parameter via SendEvent<T>, but CheckEvent<T>- and CheckEventValue<T> ignore such events and only fire when the incoming event is not null.

      Looking at the sourcecode, it looks like this is intentional behaviour at least for CheckEventValue, but I wonder why. Are there any downsides to allowing null values in event parameters? Anyway, due to the design of some components in our current project I need events to work with null parameters, so I patched both Conditions to explicitly allow null values.

      Maybe this is useful to others or maybe this is just a bug.
      [EDIT] Forum Software doesn’t allow upload of ZIP files, so heres the diffs inline:

      #17238
      Gavalakis
      Keymaster

        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.

        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.

        Thank you!

        #17237
        step
        Participant

          [quote quote=13394]Null should definitely been possible to send (and compare with CheckEventValue)[/quote]

          Thats good to hear. Thanks for the quick response and the patches!
          CheckEvent.cs did error out on FirstOrDefault because System.Linq wasn’t imported. No biggie though and the patches seem to work fine as far as i can tell. 🙂

          Cheers

          #17236
          Gavalakis
          Keymaster

            You are very welcome and thanks for letting me know it works for you as well.
            Indeed, you need to be “using System.Linq” 🙂

            Thanks!

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.