Download

Interface vs Function/event

Hello Guys,
I saw a lot of abuse about the interface around the ‘internet’ (tutorial, documentation and so on). However I want be sure that my perception is good or wrong.
My opinion is that the interfaces should be used for what they actually are: the interfaces “describe” what methods should have a class - nothing else (and that is the same as the interface of java\c++).
In my opinion there is not so much sense use an interface for the communication between two Blueprints. I also read the documentation and actually there is a paragraph that explains that it could be used for such situation - but it doesn’t mention that it is a best practice or better than use a direct function.
The fact is: If I need to call an interface implemented in a bluprint from another blueprint I **always **need the “target” object - so my question is: Why should I use an interface for the communication and not a simple function\event in the target blueprint ? The result is the same and I think it is more clear than implement an interface for this use.

What do you think about that ? Am I wrong ?

Many thanks for any clarification.

What an interface gives you that direct communication doesn’t, is anonymity.

You talk to ‘Actors’ with interfaces, not classes.

The most important take home from this, is that the blueprint doing the calling doesn’t need to know ANYTHING about the actor it’s calling the interface on. It’s a black box to it.

It means that you can segment, or isolate, parts of your code from other parts, which is a good thing.

To give you an example ( which isn’t easy to explain ), I had save game which included a user defined structure. Because all the blueprints in my game knew about the save game, the also knew about this structure. Problem was, the structure also had references to other user defined blueprint classes.

In the end, it formed a cyclic reference loop, which kept crashing the game, and took a very long time ( 3 months ) to find.

I re-wrote the save game access with BPIs, BOOM - no more problems. Because instead of the save game begin a conduit between all classes in the game, it became a brick wall.