Announcement

Collapse
No announcement yet.

Simple Blueprint Event system using UE data asset

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

    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

    Click image for larger version

Name:	1.PNG
Views:	195
Size:	262.4 KB
ID:	1656517

    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

    Click image for larger version

Name:	2.PNG
Views:	235
Size:	72.7 KB
ID:	1656502
    Click image for larger version

Name:	3.PNG
Views:	199
Size:	61.0 KB
ID:	1656503


    3.Now we can make Data Assets from SimpleEvent_BP

    Click image for larger version

Name:	5.png
Views:	189
Size:	574.7 KB
ID:	1656504
    Click image for larger version

Name:	6.PNG
Views:	191
Size:	48.5 KB
ID:	1656505



    Click image for larger version

Name:	7.PNG
Views:	187
Size:	20.2 KB
ID:	1656506

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

    Click image for larger version

Name:	9.PNG
Views:	188
Size:	35.5 KB
ID:	1656507

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

    Click image for larger version

Name:	8.PNG
Views:	190
Size:	111.5 KB
ID:	1656509

    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.

    Click image for larger version

Name:	10.PNG
Views:	189
Size:	109.2 KB
ID:	1656508






    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…

    Click image for larger version

Name:	11.PNG
Views:	190
Size:	99.9 KB
ID:	1656510


    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.

    Click image for larger version

Name:	17.PNG
Views:	191
Size:	30.9 KB
ID:	1656516
    Click image for larger version

Name:	13.PNG
Views:	187
Size:	24.9 KB
ID:	1656512
    Click image for larger version

Name:	14.PNG
Views:	190
Size:	36.2 KB
ID:	1656513

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

    Click image for larger version

Name:	16.PNG
Views:	191
Size:	37.7 KB
ID:	1656514


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

    Click image for larger version

Name:	15.PNG
Views:	192
Size:	75.3 KB
ID:	1656515

    Now test run it…Boom….
    Attached Files
Working...
X