Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

EventMan: the Event Management system you need

Discussion in 'Assets and Asset Store' started by Graph, Jun 11, 2015.

  1. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Heyo, I thought I'd make a thread to inform all you awesome people of my latest little project, an Event Manager. Now I know what you might think but it does bring features and performance better than any other system I've tested on the Assetstore.

    What is it?
    Simply put: an Event System based on the Reactor pattern..

    * Send/Receive simple Parameterless Events
    * Use ANY object as an event name<T>
    * Send ANY object as a message<T2> parameter
    * Send events with Delays ((int)frames or (float)seconds)
    * Event name overloading (Send the same event(name) to different subscribers/listeners depending on their receiving function's signature)
    * Send the same events to instance and/or static events
    * Tuples, Tuples for everyone :cool:
    * Thread safe
    * Easy to use
    * Quite performant
    * Fully documented non-blackBoxed code

    Docs: Online
    WebGL - Player
    Get it: AssetStore

    Video - Intro


    Video - Getting Started


    Video - ohh it's surprisingly fast
     
    Last edited: Jul 15, 2015
  2. Skyboard_Studios

    Skyboard_Studios

    Joined:
    Jul 20, 2013
    Posts:
    51
    very nice! 0.74ms for 1600 subscribers! I think you are on a winner. When is your ETA on release?
     
    ZJP likes this.
  3. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    That depends on the additional feature requests I get
    but as it stands now with ugui support, verbosity level based logging, delayed subscription overload and delayed parametered overloads should take me maybe a day or 2
    creating some good example scripts and scenes showing all of the current features another 2.5 days
    finishing the xml documentation and inline code documentation about a day

    so i think about a week
     
  4. Skyboard_Studios

    Skyboard_Studios

    Joined:
    Jul 20, 2013
    Posts:
    51
    i was pondering on a few ways I could use a slick event system in the game i am currently developing. One of the big issues I am facing is dealing with objects that have to synchronize over the network with RPC calls. So I am serializing data on a frame by frame basis and then de-serializing it on client machines for a synchronized game. Adding some nice networked eventing could be the key.
     
  5. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    +1 to the networking. It seems a bit tough to figure out agnostic way of dealing with the issue. But I do know my year plus long built event system desperately needs and update and you have a lot of interesting features here I see a lot of other event systems do not have. Also thank goodness for source access. I would pay a bit more for these. Voted.
     
  6. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    the networking is like an interesting problem. One thought I'm having is to queue up all messages from the publish calls and on the next update all are deQueued and published.
    each client would push their events to the server, then the server updates the queue pushes it out to all clients and on the next update call each instance would publish the same events.

    since I've never done networking for a game I'd love to hear your thoughts on that idea.
     
  7. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Hahaaa, I finally got a good name:

    icon_precise.png
    The Event manager you need. :D

    Atm I'm still working on docs and Examples. Things have taken a bit longer since I've put the system through it's paces in some actual production projects and it works nicely, can't wait to release it for others to have a go at.
     
  8. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
  9. sballew7

    sballew7

    Joined:
    Sep 3, 2013
    Posts:
    76
    Are messages type safe?
     
  10. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    yes and no :p
    it's NOT possible to produce runtime errors by sending the wrong typed message.
    but it is possible to overload event names with different message types for different listeners/subscribers (if there are however no subs that fit the message you sent it's gonna tell you in a warning.

    example:
    publisher:
    Code (CSharp):
    1.  
    2. EventMan.Instance.Publish("Clouds_ColorScale", Tuple.Create(this, color, new Vector3(scale, scale)), 0.25f * i);
    3. EventMan.Instance.Publish("Clouds_ColorScale", Tuple.Create(this, color, 10, 0.25f * i);

    subscriber:
    Code (CSharp):
    1.  
    2. EventMan.Instance.Subscribe<Tuple<Color, Vector3>>("Clouds_ColorScale", OnColorScale);
    3. void OnColorScale(Tuple<Color, Vector3> message) {..}
    4.  
    5. EventMan.Instance.Subscribe<Tuple<Color, int>>("Clouds_ColorScale", OnColorScale2);
    6. void OnColorScale2(Tuple<Color, int> message) {..}
    7.  
    I'm using strings for event names and tuples for message objects in this example but they can be anything you want them to be
     
  11. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    oh totally forgot to mention.. the eventManager is set up as a partial class
    so you can create you own specialized overloads in a non destructive way that'll be compatible with future versions.
     
  12. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Last edited: Jul 1, 2015
  13. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Bookmarked. :cool:
    You're late :p:D

    BTW i can't run any WebGL demo. :confused:
     
    Last edited: Jun 30, 2015
  14. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Heh, yeah i ran into a bit of trouble with my fancy pants singleton baseClass when loading levels.
    Since in my projects i don't have separate levels as such i didn't find that problem earlier. Not to worry tho that problem is now fixed. And it works with additive and standard level management.
    All it does require now is that you have an EventMan component in the current level. Made convenient with a prefab of course.
    I'm currently recompiling and uploading the examples, and docs with the adjustments. Then I'll make a short video and the store graphics. So if nothing else goes wrong I'll be finished today and it'll be up as soon as it has been reviewed.
     
  15. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Aaaaalrighty
    so i finished the first itteration of EventMan and submitted it. Now we wait.
    In the meantime you can watch these videos to pass the time.

    Intro:


    Getting Started:
     
    Skyboard_Studios likes this.
  16. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Nice. ETA with the functionalities shown in these videos?
     
  17. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    oh that's the one i published; it's just waiting for approval atm. I'll probably redo the getting started video in a more structured way and also include the version independent extensibility.

    btw since i packed the webGL differently now; is this one working fine for you?
     
  18. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
  19. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    Hi
    Just bought an EventMan asset and was figuring out how it works under the hood.
    Found warning that part of subscription logic will never be called:


    :101 EventSubscription.cs
     
    Graph likes this.
  20. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Oh thx, didn't see that there, should ofc be !=

    How do you like the rest of it so far?
     
  21. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    I'm new to reactor pattern but seems like EventMan does all I've expected him to and implemented in a proper way.

    I plan to use it a lot so I'll get back with comment as soon as I'll get the feel of it.
    Do you know if there might be any problems using EventMan on iOS?

    PS: Also I've noticed some starting points of NetworkedEvents. Do you plan to provide them (ie on top of HLAPI)?
     
    Last edited: May 23, 2017
  22. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    I haven't tested it on ios but I'm 30% sure it works. :p

    There are currently no plans to go into networking.
     
  23. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    How Tuples are meant to be used (any near-real example)? Do's & Dont's?
     
  24. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    Since you're limited to 1 message object I wanted to throw in something akin to a hardcoded anonymous type, so just use 'em like that :)
     
  25. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    Actually I'm disappointed after cleaning up of unfinished stuff and using EventMan for a while.

    Reasons:
    1) Needs cleanup of unfinished and abandoned networking related classes/methods.
    2) After cleaning up it's nothing more than 3 classes (not taking into account 8 Tuple classes):
    a) EventMan - event dispatcher, for subscribing and firing parametered/unparametered events. Could run coroutine to postpone events by given timeout.
    b) BaseSubscriber - only for a callback OnDestroy to auto-remove it's subscriptions. But is pointless until you find & fix a bug in EventSubscription (mentioned above by me).
    c) EventSubscription - kinda handler delegate with params with unsubscription in case of target is BaseSubscriber.
    d) Nope, nothing more than that. So IMO the price of 21$ is a way too high.
    3) GC.collects:
    a) You use Dictionary<object, List<EventSubscription>> (to store subscriptions) - this allows to store value-type objects (enums, ints) as a keys. You even provide examples with enums. Which will lead to boxing/unboxing (and therefore to GC.collect spikes) on every Publish/Subscribe, which are meant to be often.
    b) EventMan.PublishParametered uses LINQ which also leads to unnecessary GC.collects every time it's called (meant to be often), though could be easily replaced.​

    I've removed your package and will not use it any more.
    Money back will be appreciated but is up to you.

    PS: Eventually found similar pattern realization as a part of MasterServerFramework(free): http://u3d.as/Abb
    It's located in EventsChannel.cs, which also has nice features:
    1) Allows you to have multiple EventChannels, it's not static singleton class (though you could make it's static instance)
    2) 'Promises' feature for asynchronous continuation logic.
    3) Could unsubscribe all handlers on scene unload which is nice to avoid 'zombie objects' (when you forget to unsubscribe object's handler it never got GC-collected).
    But I've changed the way it handles handler's parameters
     
    Last edited: May 27, 2017
  26. rigidbuddy

    rigidbuddy

    Joined:
    Feb 25, 2014
    Posts:
    39
    Added user review on the asset store page