Casting to Interface vs Actor

I think you are missing the big picture of all this. performance tricks like interfaces and whatnot are important for repetitive, time consuming tasks. then is my understanding that one needs to implement C++ code, optimized and the rest.

Interfaces aren’t performance tricks.

So if you are checking the health on your player once a frame is like a drop a in a huge bucket of available computer power. Checking the life on 10000 Ai actors may probably be an issue and you need some custom high level stuff. maybe. Or maybe the engine is optimized to do this anyway.

Checking health on tick is generally bad practice even from a non-performance standpoint.

What I found useful for the interfaces is that I can reuse the code if for example I change the name of the player class blueprint. now someone told me on this forum that I can cast to the base class. But I’m not sure I can then use the custom functions from the child class.

Interfaces in C++ and Unreal are implemented via multiple inheritance. You’re just adding another class to inherit from that doesn’t really have anything but function declarations.

Interfaces allow us to avoid those deep inheritance hierarchies which make the code monolithic and too hard to change after the fact. Inheritance in general is at it’s best when the inheritance trees aren’t deep.

This is a mental trap I got tangled all the time. Starting to think about performance like I’m creating some sort of high level real world Formula 1 car that needs everything ultra-optimized, when in reality I’m building a wooden cart.

Rather than performance it’s better to think what sections of code can be decoupled from the rest. That makes it easier to change later on when changes made don’t have large cascading side-effects.

5 Likes