I know how to make a door as a separate actor but I want to make a car door that when you interact with it it opens or closes, how can I do this because normally it’s a Linetrace from the camera to get the actor your looking at but I only want to interact with the door when looking at the door and not the whole car, so I can’t get the actor as it would get the car.
• override a static/skeletal mesh component and script the opening inside it, the interface implementation goes here. This is a cheap, neat, and modular solution; do note that components cannot own timelines. Either use a timeline in the underlying actor, or skeletal anim for the mesh (probably the most optimal), or a timer, or Tick in the door. Too many options, actually. Depends on whether you have 1 car and 1 door. Or an entire parking lot to deal with.
• or, when the trace hits, you get both, the actor and the component. Have the interface in the actor and make it operate on the component. Easier to implement and more centralised but the approach is not that modular and not scalable. Could work OK if the scope is small.
• or, have something more decoupled and agnostic. The entity that does the tracing -ideally, the player controller - manipulates the detected actors / comps. Optionally, this could be the player rather than PC.
All the above are viable under certain circumstances. And having an interface would be handy in all cases. But the implementation would vary.
You then get a component blueprint that already sports a Static Mesh Component but it now also hosts a graph, can have variables, functions, interface implementation and so on:
You can now script all the things the door needs to know about right into the door:
Add Custom Static Mesh Door comps to the car actor, as many as necessary:
Each can have a different mesh, exposed variables and so on.
When the trace hits something, message the instance via the interface:
The car does not even need to know about it. Which is great. However, it’s trivial for the door the talk to the car and trivial for the car to talk to its doors. Either with Event Dispatchers and Direct Comms or with the Interface the door already has.
Let’s say the car decides to open some of its doors:
This is a great way to build modular actors. Like a shelf with a bunch of drawers, or a robot whose each limb has a life of its own. Or pieces of armour that can be peeled off a tank - each capable of tracking its own status.
Essentially, you end up injecting logic into an otherwise dumb Static Mesh Component. And then build more complex systems out of the now smarter components.