Download

Clarifying the relationship between UActorComponents and Actors

This is a code design question more so than an API or “how to” question. I’m finding myself at a little bit of a loss on the component system, mainly because the relationship between UActorComponents and Actors seems a little bit ambiguous to me. UActorComponents seem to be aiming at re-creating the modular composition-based method that users might be familiar with in Unity, but at the same time there’s no reason you couldn’t extend AActor or one of its child classes and just give it the functionality you want directly. The mission statement for UActorComponent reads that it’s meant to create re-useable pieces that you can employ across as many kinds of actors as you want; yet, it seems like if they spend a lot of time “reaching up” to access and modify their parent actors that this would lead to a lot of annoying spaghetti code.

What I suppose I’m trying to ask here is: what are the best practices for handling UActorComponents vs. extending Actor classes? Are UActorComponents meant to be able to manipulate and extend their parent Actor? Or is it the other way around, with UActorComponents meant to act as Sub-Objects that the Actor then “reaches down” to and manipulates? While I realize that the possibility of both does exist, I’ve got to imagine that the community has some idea of the best practices for using these methods. What’s worked best for you when dealing with this, and why?