Simple Blueprint Event system using UE data asset

Hi Guys,

I’m a beginner in Unreal engine. I use Blueprints only for scripting as of now.
I’m good at unity3D and I been using event-based design pattern in my projects for a while. And I use Scriptable objects for making for this system. It is something like event assets. You can take a reference to this event asset inside an invoker and inside a listener. And the result is no tight coupling. While I started using UE, I thought this can be made happen in UE also. But I couldn’t find any result from internet/forums. So, I decided to make of my own.
I’m not sure if people are using this method, still I’m sharing the system here.

Unity Scriptable Objects = UE data assets. Mainly used as data container assets but you can do more with them…

1.Let’s make a project first

2.Now make a blueprint with PrimaryDataAsset as parent class
I’m naming it as SimpleEvent_BP. Open the Blueprint editor and declare an eventDispatcher. “SimpleEventDispatcher”
Done!! Our SimpleEvent Blueprint is ready


3.PNG

3.Now we can make Data Assets from SimpleEvent_BP


6.PNG

7.PNG

4.Now we can make an invoker ActorComponent to invoke this Event assets.

9.PNG

5.Edit the SimpleEventInvoker and make a variable to refer to the SimpleEvent Data Asset and a function InvokeEvent to invoke the SimpleEvent…

So our invoker component is ready
Now we can make a listener ActorComponent

Just as in SimpleEventInvoker, we can add a reference variable to refer simpleEvent. Also a dispatcher OnsimpleEventInvoked.

Now the event subscribing part…
Create a custom event SubscriberEvent to bind to the simpleEventDispatcher on beginplay and unbind on endplay…
This subscriber event will act as an intermediate that will call OnsimpleEventInvoked dispatcher when invoked…
As a result all the external events binded to OnsimpleEventInvoked will get invoked…

So our invoker is also ready. Now we can test it…

Make two actor Blueprints ExampleInvoker_BP and ExampleListener_BP
On ExampleInvoker_BP add actor component SimpleEventInvoker and add SimpleEventListener on ExampleListener_BP. On both components, select ExampleEvent in the exposed field simpleEvent.

17.PNG
13.PNG

Now in the ExampleInvoker_BP, add a key pressevent and callfunction invokeEvent

16.PNG

And in the ExampleListener_BP, bind a custom event to the dispatcher of listener…

Now test run it…Boom….

5 Likes

Genius Mr.777!

I know this is an old thread… but I haven’t seen this discussed elsewhere.

I’m also a Unity dev fully switching over to Unreal and this exact same pattern of using Scriptable Objects for an event system is what I used in Unity. I know Data Assets are basically the Unreal equivalent of Scriptable Objects so I was hoping something like this would work.

My question is… are there any drawbacks to doing it like this in Unreal? I know it works and is even encouraged by Unity devs for that Engine. But I’d love to know what an Unreal dev thinks about this method of an event system.