Announcement

Collapse
No announcement yet.

[Plugin] Event Aggregator (Global Event Handler) for Blueprints and C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [RELEASED] [Plugin] Event Aggregator (Global Event Handler) for Blueprints and C++

    LINK TO THE MARKETPLACE: https://www.unrealengine.com/marketp...andler-for-ue4

    Hey guys, i've been developing a plugin for Unreal Engine, to allow using the event aggregator pattern in your projects. Inspired in my journeys trough .NET lands (using frameworks like Prism and Caliburn Micro) i ended up realizing that Unreal could really benefit from an event aggregator that is easy to use (specially as easy to use as the Caliburn Micro's event aggregator).

    For all the people that doesn't know what an event aggregator is: An event aggregator pattern allows to anonymously communicate and send messages (payloads) from a Publisher object to one or more Subscriber objects. The publisher doesn't need to know who is listening the message (if any) and the subscriber object doesn't need to know either who is sending that message.

    In Unreal Engine, this is very advantageous since the only method we have to communicate anonymously is the UInterface, and it doesn't really work in an anonymous way since we still need the raw reference of an object (raw=not casted) for sending a message. Obtaining that reference could be complicated sometimes, we could get that reference using "GetAllActorsOfClass" (which is slow and also adds a direct dependency to the class) or we could expose an Actor variable in the view-port and link the reference there (which doesn´t work in level streaming scenarios unless soft references are used, also doesn´t work when Actors are spawned in runtime).

    So, what my plugin does to "fix" that is to allow sending messages between objects (UObjects, Actors, etc) in an anonymous way. You could send a message to hundreds of different Actors (Of different types) without even knowing if they exist.To better explain how it works, i will show you the current workflow (note that some things may change in the final version):

    # First: We need to create event objects (which will act as signatures for filtering who receives the messages).

    Click image for larger version  Name:	1.jpg Views:	0 Size:	14.3 KB ID:	1707120
    Additionally, we could create variables inside these event objects, so we could also use the instances of the events as payloads (extra content of the message) as well, although any UObject could be a payload.

    Click image for larger version  Name:	2.jpg Views:	0 Size:	282.2 KB ID:	1707121

    # Second: We publish a message in the Publisher UObject/Actor

    Click image for larger version  Name:	3.jpg Views:	0 Size:	224.8 KB ID:	1707122
    As you see, i´m using a Subsystem (GameInstance based) to invoke the Publish event. The "class to listen" is the class of one of the events created in the first step. Any Object subscribed to that event class will receive the message. The Payload and Metadata is optional. And as i mentioned before, the payload could be the reference of any UObject, although i prefer to use an instance of the same Event (Event A) as payload. The instance of the payload can be created using the construct object method, as shown below.

    Click image for larger version  Name:	4.jpg Views:	0 Size:	103.1 KB ID:	1707123

    Also, i plan to also give the option to use a LocalPlayerSubsystem and WorldSubsystem as well, to publish and subscribe messages in those contexts and allow for a better flexibility using the system.

    # Third: Subscribe and Listen for messages.

    Click image for larger version  Name:	5.jpg Views:	0 Size:	345.3 KB ID:	1707124
    In the subscriber, the only thing needed is to call the Subscribe() method, link it to a Custom Event and that´s it! The custom event fill be fired whenever an object publish a message to EventA.
    Notice that i´m not using components or interfaces to achieve this functionality. Just two methods, pretty easy!

    Of course, there´s also methods for unsubscribing, debugging, etc. Unsubscribing is also made automatically if the subscribed objects were destroyed.

    ---

    Additionally i plan to take advantage of the UE framework and to give more options on the publish/subscribe method. For example: publish a message to EventA that will only be received by Objects of type Actor, that implements InterfaceA and has ComponentB attached. Although i´m not sure if the last part will be shipped, since it can be done by using the payloads and branching on the subscriber and i´m not sure yet how it will affect the performance of the plugin. Although currently, the system is lightning fast.

    Also, notice how in the example the only dependency of both the publisher and subscriber is the "EventA" class. This is pretty nice since without the direct dependencies, the objects are now more reusable and testable as well!

    ---

    For finishing, i plan to submit this plugin in a few days. And i plan to release it for free in the first days. Although i´m not sure if this is possible to do in the marketplace, i will be sending a message to the staff to confirm if it can be released for free temporarily.

    I will be updating when the plugin is going to be released so you can get it for free. I only ask you guys to give my plugin a chance and try to review it in the marketplace (but please take into account that the plugin may have issues that will be fixed in the first days with the help of your feedback ;p). However, you´re not obligated to review my plugin, so don´t feel bad if you´re not a reviewer type of person =D.

    So guys, hopefully you liked my post. If you have any feedback or question, please comment below!
    Last edited by Cronofear Dev; 02-06-2020, 03:35 PM.

    #2
    Hey guys, the plugin has been released and can be grabbed for free temporarily.

    Comment


      #3
      That's fantastic, thank you! I will check it out now!
      Gaming Forums

      Comment


        #4
        Thanks for this!

        Comment

        Working...
        X