As it is obvious from my question: I’d like to know how interface message works from a programming point of view.
The reason I’m asking is because I’m also using Unity and I wanted to achieve the same functionality I have in Unreal using interface message.
An example: I use line trace as part of a laser gun, and then I send an interface message (let’s call it “TakeDamage”) to the hit result, which calls its own TakeDamage function if it implements the interface.
Now in Unity, every method to achieve this seemed too complicated and also not performance-friendly, at least compared to Unreal’s method (as Unity doesn’t have the exact same option).
Though I may be mistaken, and perhaps this interface message in Unreal is more complicated in the background than it looks.
So that’s why I’m interested in how it really works, because I’d like to use the same method in Unity possibly with not much difference in performance.
So if you know how it works in C++, and how I can do the same in C#, please share. Thanks you in advance
I find this useful. From my limited experience, second paragraph is exactly how it would be done in ue4 - create interface, implement into class, call it from another class.
Zak does a great job of explaining all Blueprint communication methods in this video. You can start from this segment to understand how Unreal implements blueprint interfaces. Watch the entire video for all communication options. In your specific example you do not need to use interfaces at all. I would just use Apply Damage and Event AnyDamage to handle those mechanics.
Its basically little bit more complex c++ virtual function, i dont know how fast they are in c++ compare to unity, dunno if anyone would even bother to answer or test it anyway. If you using blueprints, its one of the fastest and definitely easiest from reliable ways to go, if you using c++, it’s preferable way to go, which probably means its fast as well.
Also, you didn’t even said what is the “method” in unity and why even comparacing to unity does matter for you. Thats different engine, using different language, its may be faster or slower, but that’s how stuff done here.