Say you have a car. And you can interact with its elements, like the doors, trunk, radio etc. These elements need to have their own functionality, like their own variables, events, functions. And also be able to attach actor components to them.
What’s the best way to create that? Is it child actors or sometihing else?
Thanks.
You need to make a single actor component for interactions system that can handle multiple interactions under a hierarchy. Like array of interaction points that takes some arguments : Interaction Name : SceneComponent
Under hierarcy you can create a new scenecomponent addition like : InteractableSceneComponent
assign as mentioned to array.
Now you have specific scene components coralated with some actions data, in specific places of car.
You have to select what player is trying to interact depending on the camera look or someother method and prioritize current interaction for player. UI works also here to get position from world to screen and show indicators.
When player press a button to interact, you need to catch current interacted element and dispatch an event for that particular element in InteractionActorComponent
After Interacted event has happened, you can branch into specific gameplay logic, door open get out, radio switch etc.
If you want to be more tidy and design wise more extendable, you can use GAS for catching these events and they activate specific ability on car, CarAbilityRadio_ABP->TuneForward/Back. That way you don’t have to make radio tuning for each car logic, car radio tune becomes agnostic from car vehicle itself.
If you want to be more simple,
A simple actor with interaction data
When Actor is between camera angle some degrees show ui
Oninteraction fire an event with data
Catch that event in vehicle and do whatever.
Now you can place multiple interaction actors in car and attach them to sockets.
Prototype wise this approach ok, production wise would create many problems and won’t be usefull in long term UX wise.
I should’ve mentioned I’m using blueprints. Not familiar with c++.
I already have a rudimentary interaction system based on line trace and a blueprint interface applied to each interactable actor.
The reason I wanted to have the elements on the car separated from each other and from the car itself, is because I need to be able to destroy them without breaking the car functionality. Also I need to “save” data for each of those car parts individually, when I save the game.
I’m not sure I understand how to use scene components to achieve that.
It’s ok you can do with that system. Here is how and the additions you need to make.
- Interactable Actors(With Interface): Make sure interactable actors have states like : IsOn , Is Off, you can make an blueprint enum or just a bool. On each actor they need to retrieve their state IsOn or IsOff from you save system on BeginPlay.
- Interactable Actors : Interacted : Make sure the interactable actors directly connected to its car functionality. Like DoorOpen/Close. On begin play when InteractableActors retrieve state, they can also set the car states ready this way. After an interactable actors state received from SaveGame they fire an event or function to do those for you. It is better to have an event like InteractableActorStateChanged event with bool.
- InteractionSystem : When player presses a buttton, it should talk with the Current InteractableActor through interface and tell its interacted. OnInteracted it should fire previously integrated OnInteractionStateChanged Event.
This way Interaction System doesn’t care about the Interacted Actors functionality.
To Recap
Communication Graph
InteractionSystem → Interface → Interacted Actor ->InteractionStateChanged(Event)-> Listener (Car)
You don’t need to do car a big interactableactor, you can make mini invisible actors placed in car, that change state, fire event.. and car listen those actors for specific functionality.
That’s what I need to know. Should I attach those interactable actors as child actor components to the car actor? Or can I just attach them to the car actor, in the viewport, or through “Attach actor to actor” node at runtime if needed?
What are the downsides to each approach, if any?
I think go with AttachActorToComponent to assign them to skeletal mesh of car, with sockets can be nicer.. you can use AttachActorToActor if your structure doesn’t enables you to use otherwise.
Carefull about the collision channels to overlap or ignore besides interaction channel so you don’t have trouble with cars movement etc.
In terms of downside its hard to tell without knowing your systems deeply however, I see some pain points integrating this system to a car. I would have designed a Inherited interaction class for vehicles in that game so it becomes more managable: Like I can detect sockets on car’s mesh and assign interactions to there etc. There is much more than that to talk about pros and cons about a system especially when it comes to modularity. In the end If it works, it works..
A system in a game quality can be measured by
- Functionality: how efficient it is in complex gameplay situations: EX: I can’t use an interaction outside of the car through windows etc.
- Usability: How easy to use for player also for developers/designers. From integrating interactions to a new car, to debug.
- Extendability : How modular it is if and unexpected mechanics arise to be implemented to existing architecture without exceptions. Forethough, this comes with experience, design thinking and design theory and requires critical thinking.
Let’s not forget how fun, easy, meaningfull it is to use for player. Which is another subjects that every designer tries to tackle in daily lifes.