Unity VR Interactions-Slicing GameObjects
Unity VR Interactions-Slicing GameObjects
Course Details
Instructor: Adam Wright, PFS / CDM
Author: Adam Wright, PFS / CDM
Class: CDM 176: Special Topics in Game
Development - Virtual Reality
Academic Term Spring Quarter, 2025
Academic Institution: University of California at Davis
Technical Specifications
Unity Editor version: Unity 6 (6000.0.24f1 [LTS])
XR Interaction Toolkit version: 3.0.8
XR Plugin Management version: 4.5.1
VR Device: Meta Quest 2
Requirements
A Unity project that is:
● Configured for VR
● Containing a functional scene
● Containing “sliceable” GameObjects
● Containing a grabbable “slicer” GameObject
● Containing a functional XR Origin with configured right and left controllers
● Containing Valve’s Velocity Script (this can be found on Canvas)
● Containing David Arayans “Ezy Slice” procedural mesh generation framework for
slicing
● Configured for building to the Meta Quest 2 headset, with the correct project
settings
● Configured with a functional text editor
Overview
This tutorial covers how to “slice” through GameObjects in your scene. For ease-of-use,
we will be using a well-known open source mesh slicer framework for Unity created by
David Arayan called Ezy-Slice. This framework utilizes procedural mesh generation that
identifies the vertices on either side of a plane used to “slice” a GameObject. In addition
to this framework, we will also be using Valve’s VelocityEstimator script.
Getting Started
This section covers adding and configuring “slicer” mechanics in our Unity project that
can be tested using a plane intersecting with a “sliceable” GameObject on a simple
keystroke. Later we will convert this into mechanics that can work with our prefab
“slicer”.
Right click in your Scripts Folder and create a script called “SliceObject”
Open your script. Add the following reference in the header that refers to the EzySlice
framework:
● using EzySlice;
Next, add two public variables under the public class SliceObject:
This logic performs a check to see if there is GameObject (target variable) to be sliced,
and if so, will create an upper and lower “hull” GameObjects, on either side of the plane.
Step 5: Add Test Logic to Perform a Split Along the Axis of the
Plane Intersection
In this section we will add some test logic (logic we will replace in later steps) to see if
the split mechanics are working. We will be using a spacebar keypress as our input for
this test.
● “Using UnityEngine.InputSystem”
● If (Keyboard.current.spaceKey.wasPressedThisFrame)
{
Slice(target);
}
Step 6: Add Script to “Slicer” GameObject and Configure
In this step, we will add the SliceObject Script to our “Slicer” GameObject and add the
Plane Debug GameObject and Target to the Script Component.
2. In the Inspector Window, click Add Component and add the script called
“SliceObject”
3. In the SliceObject Script component, add the plane to the Plane Debug
Transform field
4. In the SliceObject Script component, add the “sliceable” GameObject to the
Target GameObject field (in my case, I am using a blue cube
While in Play Mode, after hitting the spacebar in the Game View, and
switching back to the Scene View, you should be able to see and do the
following:
Note: at this point this “splitting” has produced two new game objects that are
essentially parts of the original GameObject. However, you’ll notice that the original
GameObject is still present in the scene. This is because “slicing” a GameObject is
really just creating two new GameObjects, and then destroying the original to produce
the illusion of “slicing.”
In the “upperHull” and “lowerHull” logic, in the Slice add the following to create a new
material for the exposed side of the sliced GameObject:
Additionally, in the “SlicedHull” function’s “if” statement, add a line at the end to destroy
the original GameObject:
● Destroy(target);
1. Create a new material for the Cross Section Material public variable you’ve just
implemented in the script
2. Click on the “Slicer” Prefab / GameObject (in my case its the “Sword” prefab)
3. In the Inspector window, locate the Slice Object Script component and drag the
new material into the Cross Section Material field
Test this the same way you tested in Step 5.
Add a new public float variable called “cutForce” and give it a value of 2000:
____________________________________________________________________
Rigidbody component
● Checked the box for “is kinematic”
● Changed the Collision Detection to “Continuous”
Add the Prefab GameObject “Slicer” to your scene
In your scene, add the prefab “slicer”. Place it near the “sliceable” GameObject
3. Move the “Start Slice Point” Empty GameObject to the base of the “blade”
section of the prefab.
4. Move the “End Slice Point” Empty GameObject to the tip of the “blade” section
of the prefab.
5. Click on the “End Slice Point” Empty Game Object and add the
VelocityEstimator script to it as a component. After added check the box for
“Estimate On Awake”
Step 6: Configure Slicer Mechanics in Unity Editor Inspector
In this step, we will configure the Slicer Mechanics made available to the Unity Editor
through our public variables. Additionally, we will make a new layer that masks the slicer
interaction and assign it to our “slicer” prefab SliceObject script component.
1. In the “Start Slice Point” field, add the “Start Slice Point” Empty GameObject
you’ve just created.
2. In the “End Slice Point” field, add the “End Slice Point” Empty GameObject
you’ve just created.
3. In the “Velocity Estimator” field, add the “End Slice Point” Empty
GameObject (that the VelocityEstimator is attached to.)
Step 7: Create and Add a New Layer Called “Sliceable” to
GameObjects you want to be able to slice
In this step we will create a new Layer called “Sliceable” and add this layer to all the
GameObjects you wish to be able to slice. This compartmentalizes slicer interactions
from other types of interactions using Unity’s Layer Mask feature.
1. In Edit / Project Settings / Tags and Layers add a new layer called “Sliceable”
3. Select your Slicer GameObject. In the Slice GameObject Script component
add the “Sliceable” layer to the Sliceable Layer dropdown.
Step 8: Add all GameObjects for Slicing to the “Sliceable” Layer
In this step, we will add all of the GameObjects we want to be sliceable to the
“Sliceable” layer we’ve just created.
● Add the following to the “upperHull” and “lowerHull” logic in the Slice function’s
“if” statement:
upperHull.layer = target.layer;
lowerHull.layer = target.layer;
● XRGrabInteraction grabbable =
slicedObject.AddComponent<XRGrabInteractable>()
In the Slice() Function “If” statement add a new local variable called originalGrab to
preserve the dynamic attach:
● SetupSlicedComponent(lowerHull, originalGrab)
● SetupSlicedComponent(upperHull, originalGrab)
In the parameters list, we will add a new XRGrabInteractable parameter, like this:
Add an “if” statement that reestablishes the Grab with Dynamic Attach properties:
If (originalGrab != null)
{
grabbable.interactionLayers = originalGrab.interactionLayers;
grabbable.movementType = originalGrab.movementType;
grabbable.throwOnDetach = originalGrab.thowOnDetach;
grabbable.useDynamicAttach = originalGrab.useDynamicAttach;
newAttach.localPosition = originalGrab.attachTransform.localPosition;
newAttach.localRotation = originalGrab.attachTransform.localRotation;
grabbable.attachTransform = newAttach;
}
else
{
grabbable.attachTransform = null;
grabbable.useDynamicAttach = true;
}
}
else
{
grabbable.useDynamicAttach = true:
grabbable.attachTransform = null;
}
Final Script