I had come across a thread in which someone talked about using Components to make their code modular, where they can snap in functionality into Actors very easily. As I look into this, it isn’t clear how to do this efficiently in BP.
So far my experience in trying such an approach is that the Actor and Component need to know something about each other for them to communicate. Even if I make an interface for the Actor to keep it generic from the Component’s perspective, this would mean the Actor has to modify.
I think it would be valuable to make Components that can snap right in without adding any modifications in any Actor blueprints, and the Components don’t require any changes to work with the specific Actors.
Is there any documentation or videos on best practices of designing Actors and Components so that they are independent of the Actors they are added to?
you can do that but it depends on your game, for instance say you wanted a physics component you could use
get owner, get component by class, primitive etc to create modular code with no hard refs.
but often they will be connected somehow
So my thoughts are that you don’t always want them to be 100% applicable to any actor.
For instance, you may have a component for health that holds the variables for how much health a pawn may have and keep track of that, then you can attach it to any pawn. (really this one could be on any actor).
There is virtually 0 way to just ATTACH a component and it be done. The whole point is to be able to take large amounts of code and reduce it to “Attach it to the character, add a reference on the character when _ happens, done” instead of individually coding it for every actor that may need this functionality.
This guy seems to have a lot to say about it, maybe you could glean some insight from this?
Disclaimer: This link is not affiliated with Unreal Engine, Epic Games, or their partners.