Building a Reusable Interaction Framework in Unity — Day 01
By Karthick Gunasekaran
I'm a Unity developer exploring gameplay programming and technical art. I want to use this space to document the systems I build, the engineering decisions behind them, the problems I encounter, and the things I learn along the way.
For my first development series, I'm working on a reusable Interaction Framework in Unity.
Rather than creating individual interaction scripts for every object, the goal is to build a modular foundation that can support different types of interactable objects.
Why build an interaction framework?
Interactions are among the fundamental systems in most games.
Opening a door, picking up an object, activating a terminal or interacting with an environmental element may appear simple individually. However, as a project grows, managing these behaviours independently can become difficult.
I wanted to explore an architecture where detection, interaction behaviour and visual feedback have separate responsibilities.
Initial architecture
The first version is built around a few core components:
- CameraDataCollector: Detects interactable objects using a camera-centred raycast.
- IInteractable: Defines a common contract for different interactable objects.
- PlayerInput: Handles the player's interaction request.
- InteractionHandler: Connects the input request with the currently detected interactable.
- InteractableFeedback: Handles optional visual feedback when an object becomes the current target.
One important decision was to use interfaces instead of depending on a specific interactable class.
This allows different objects to implement their own interaction behaviour while the framework communicates through a common contract.
Camera detection and target transitions
The first implementation focuses on identifying what the player is looking at.
I wanted the detection system to recognise three important transitions:
- Entering an interactable's detection area.
- Switching from one interactable to another.
- Leaving an interactable and looking somewhere else.
Instead of broadcasting an event every frame, the system compares the current target with the previous target and publishes an event only when a change occurs.
This became the foundation for connecting visual feedback without tightly coupling it to the detection logic.
Supporting different GameObject hierarchies
I tested two arrangements:
Test A: The interactable component, feedback component and collider are on the same GameObject.
Test B: The interactable and feedback components are on the parent, while the collider and renderer are on a child.
Supporting both arrangements is important because an interactable's logical behaviour does not necessarily need to live on the same GameObject as its visual representation.
Debugging the material feedback system
One of the interesting challenges was getting runtime material swapping to work correctly.
Initially, I used a fixed-size material array with 15 elements. This caused problems because the array size did not necessarily correspond to the renderer's actual material slots.
I changed the implementation to create the material arrays dynamically based on the renderer's existing material count.
That resolved the visual feedback issue, and the highlight material is now being applied and restored correctly.
A small debugging exercise, but a useful reminder to avoid arbitrary assumptions when working with Unity's renderer and material APIs.
Visual development
Alongside the programming work, I used ProBuilder to improve the scene's look and feel.
This helped me move beyond testing the framework with plain primitive objects and start giving the prototype a more intentional visual presentation.
Current progress
- Camera-based target detection implemented and tested.
- Interface-based interactable identification.
- Target entry, switching, exit and reacquisition working.
- Event-driven visual feedback implemented.
- Runtime material swapping and restoration working.
- Tested two different GameObject hierarchy arrangements.
- Initial scene visual improvements using ProBuilder.
What's next?
The next goal is to complete the first version of the framework by connecting player input and interaction execution.
After that, I'll test different interactable implementations and continue improving the framework's flexibility.
This is just the beginning of the project.
I'll document the progress, technical decisions and lessons learned as the framework evolves.
Project: Unity Interaction Framework
Series: Gameplay Programming — Project 01
Status: In Development
Top comments (0)