About Interface calls performance

Hello everyone, something that has been occupying my mind for some time is related to the efficiency of blueprints and the use of interfaces.
For instance, we have a character actor that has its own interface. When we want to call the functions in the character class by other actors, are the following two methods differ in terms of performance?

  1. Using just one function in the interface that calls the character class and by using it, we can access all the functions and variables of our character.
  2. For each of the functions and entities that we want to use in other classes, define them separately in the interface and call them one by one.

The following photos express my meaning more clearly:

1: First Scenario

2: Second Scenario

Note: In first scenario, the interface function defined as shown in picture below:

In the first example, you’re missing the point of an interface. You wouldn’t use it to get a reference to your player. You would use it to update the variable.

It’s not about efficiency. If you make a separate interface for every player update, or just reach in and start tweaking variables, it doesn’t matter in terms of efficiency. The crucial point is ‘loose coupling’

Interfaces mean you can talk to actors without knowing what class they are. So your first example would become

image

What’s the point of that, you might ask!? :slight_smile:

It has two very useful aspects:

  1. You can make that call on ANY actor, so it becomes a general purpose call. Not very useful here, but if the call was something more like ‘Use’, you could image how many things that would work for ( door, gun, lift, teleporter… ), and they all implement ‘Use’ differently.

  2. You’re making the call on the player without casting, and knowing what kind of actor class the player is. That’s called ‘decoupling’. It means that if, for instance, you talk to all your weapons using interfaces, your game will only ever load the gun ( and textures etc ) the player is using. If you use cast, the player will have the code and materials of all guns loaded all the time, even though they aren’t being used.

Hope that makes some sense…

PS: If you need to set a lot of player variables, you can still use an interface, but you would probably pass a structure.

3 Likes

That makes sense, absolutly!
Thanks for your comprehensive instructions. Got my answer!

1 Like