Kanda Interactions 0.7.1
Loading...
Searching...
No Matches
Grabbing Objects

The Grabbable system provides a way to pick up and hold objects in 3D space. It works in conjunction with the interaction and attachment systems to enable natural grab mechanics that work across the network.

Core Components

Grabbable

The core component that marks an entity as grabbable. When combined with an Interactable, it allows the object to be grabbed using a specific activation type:

public struct Grabbable : IComponentData, IEnableableComponent
{
public ActivationTypes ActivationTypes; // Primary or Secondary activation
}

Key Features

  • Network synchronized grabbing
  • Attachment-based movement
  • Support for different grab activation types (Primary/Secondary (Default))
  • World-space and local-space grab offsets

Intended Use

Basic Setup

To make an object grabbable, add both Interactable and Grabbable components:

// Create basic grabbable object
var entity = EntityManager.CreateEntity(
typeof(LocalTransform),
typeof(LocalToWorld),
typeof(Interactable),
typeof(Grabbable),
typeof(Attachable),
typeof(Movable)
);
// Configure the grab activation type
EntityManager.SetComponentData(entity, new Grabbable
{
ActivationTypes = ActivationTypes.Secondary // Use secondary activation
});
// Disable Attachable initially - it will be enabled when grabbed
EntityManager.SetComponentEnabled(entity, false);

Required Components

A grabbable entity needs several components to function:

  • Grabbable: Marks the entity as grabbable and defines activation type
  • Interactable: Enables interaction with interactors
  • Attachable: Handles following the grabbing entity's transform
  • Movable: Handles movement when attached

Grabbing Process

  1. An Interactor hovers over the grabbable object
  2. When activated with matching activation type (Primary/Secondary):
    • The Interactable becomes active
    • The Attachable component is enabled
    • Transform offset from interactor is calculated
    • Object begins following the interactor's movement

Grabbing on PC

The grabbing action is different on PC platform. You can use both Q button on keyboard and Right Mouse button to grab objects. Another difference is that grabbing works like a toggle, that is, user presses on Q/RightMouse (no need to keep pressing) to grab an object and presses again to release it. For more details refer to player package documentation.

Smooth Movement

Grabbable objects use the Movable system for smooth movement. This helps reduce jitter when grabbing networked entities. You can adjust the smoothing by modifying the SmoothMovable component:

// Add smooth movement (optional)
EntityManager.AddComponentData(entity, new SmoothMovable
{
SmoothingTimeSeconds = 0.05f // Adjust for desired smoothness
});

Grab Transforms

When an object is grabbed, it calculates and maintains its offset from the grabbing interactor. This ensures the object:

  • Maintains its relative position to the grab point
  • Can be smoothly passed between different interactors
  • Preserves its orientation during movement

Network Behavior

Grabbable interactions are networked through the predicted ghost system:

  • Grab inputs are predicted on clients and validated on server
  • Attachable state is synchronized across the network
  • Movement is predicted or interpolated on remote clients

Performance Considerations

Component Enable/Disable

The system uses enableable components to efficiently manage state:

  • Grabbable can be disabled to temporarily prevent grabbing
  • Attachable is automatically enabled/disabled during grab/release
  • Movable handles position updates only when needed

Transform Hierarchy

Consider using local space attachments for root-level grabbable objects to avoid unnecessary transform calculations.