Hey guys,
Coming from a Unity3D background, I’ve been trying to replicate an event-based architecture in Unreal Engine 5.1 based on the idea presented here (starting at 5:54):
The idea is to make a PrimaryDataAsset with an event dispatcher and use data assets derived from this class as “channels”. Any actor can invoke the event on a data asset, and any actor can listen to the event without coupling either. The same idea has been presented on the forums before (Simple Blueprint Event system using UE data asset).
I tried implementing this for myself to create an audio system, but can across some very peculiar behaviour.
My implementation is as follows:
- Create a PrimaryDataAsset with an event dispatcher and a custom event to call said dispatcher and create a data asset that based on it.
- Create an actor that is responsible for implementing the logic triggered by the event, give it a reference to the data asset and have it listen to the event dispatcher.
- Create an actor that will trigger the event, give it a reference to the data asset as well and have it raise the event.
The expected behaviour here would be that as soon as I press “C”, the audio will play and the string “Play voice Audio” would be printed. (And one of the breakpoints would fire).
However… Somehow none of the breakpoints fire, the audio is NOT played, but the printstring IS printed. I was a bit flabbergasted when I saw this, cause it means at least part of the logic is working.
In a second attempt, I explicitly bound the event on BeginPlay instead of using the event UE created for me.
This approach worked perfectly and gave me all the expected results, but it’s slightly less neat.
So as to my question:
I was wondering if this is a design pattern that you would recommend in UE5?
If so, if this is the correct approach to this design pattern? (And if not, how do I prevent tight coupling without it?)
And lastly if anyone has any clue as to why the first implementation doesn’t work (but somehow DOES call the printstring)?