What advantages come from making a component versus a base class?

Hello all,
Recently, I created a movement component for a spaceship, allowing for a target location to be set and the actor with that component would move in a flying manner to that location. I know it is also possible to make this type of functionality in a base C++ class, then inherit that class to receive the same functionality as from my component. I was wondering if there were any advantages to making a component versus a base class, and why you would choose one over the other?

Thanks for your advice.

Hello, sigi0073

Please note that inheritance is usually used when there is a logical background that comes from the way objects relate. In other words, if you have several types of spaceships, you can create a base class and inherit it in order to create customized ships.

In the described situation, I would suggest specifying the requirements and estimating the future development of the game. If the project is complex and involves many classes with different functionality, creating custom components may be a good decision, since it makes your code more flexible. You can easily combine modules (components) in your classes and get the necessary behavior.

Thus, the decision whether to choose inheritance or composition is one of the most fundamental questions in object-oriented programming and the answer depends on the situation. Luckily, Unreal Engine 4 allows developers to go both ways and combine the approaches effectively.

Hope this helped!

Good luck!

Thanks! This what was I was looking for.