I know this thread will not lead to any concrete solution because there is more than one way to skin a cat. The reason I posted this thread is because finding decent information on Composition in Unreal is like finding a Unicorn. It doesn’t exist. It is very popular in Unity and Unreal has many of the same tools for Composition as Unity post-4.7. So I’m curious why there is not more information about blueprintable components for Unreal.
Let’s take the classic example of things in a game being Interactable.
Inheritance
class AUsableActor : public AActor { // some virtual functions and properties to Interact() with Actor. }
class ABaseItem : public AUsableActor { // override Interact() to Pick up item perhaps }
class ABaseDoor : public AUsableActor { // override Interact() to Open door }
Interfaces
class AUsableItem : public AActor, public IInteractable { // implement Interact from IInteractable to pick up item }
class AUsableDoor : public AActor, public IInteractable { // implement Interact from IInteractable to open door }
Finally… UE4 Composition
class UInteractableComponent : public UActorComponent {}
class UInteractableItemComponent : public UInteractableComponent {}
class UInteractableDoorComponent : public UInteractableComponent {}
// Equipable Item component to make this more interesting
class UEquipableItemComponent : public UActorComponent {}
// Item Storage (like a backpack) allowing item to store other items
class UItemStorageComponent : public UActorComponent {}
// Base Item class
class ABaseItem : public AActor
{
UInteractableItemComponent* ItemComp; // Allows and handles item pickup...puts item in character inventory
UEquipableItemComponent* EquipComp; // Allows and handles item equip through inventory
UItemStorageComponent* StorageComp; // Allows item to hold other items...can be placed on World item boxes as well to be looted.
UOutlineOnFocusComponent* FocusComp; // Allows character focus handler component to outline on mouse over
//Adding these components would make something like an equippable backpack. Each component should function independently and without care of the others or the item it is connected to.
}
You get the idea…I’m sure there are advantages and disadvantages to all 3. I’m really not sure what the ideal approach is. I really like component based design but these require more upfront engineering it seems. Discuss…