Use Action¶
The Use Action is used in situations where we need to take an object and hold it in a specific area for a predefined period of time.
To generate a Use Action you need:
The interactable prefab
The use collider
An animated hologram
In this tutorial, we will implement a Use Action where the users should take a cloth to clean the Sponza model.
Interactable prefab¶
From the MAGES menu select the option CreatePrefab/Interactable

We populate the prefab template with a cloth model as seen in the image below. Remember to add physical colliders.

Note
It is recommended to set the AttachPrefabSpawnNotifier
value from the InteractablePrefabConstructor
script to True
. This will enable a flashing animation till the object is grabbed.
We also add custom hand postures for our interactable prefab. You can read here a detailed tutorial on how to properly setup hand postures. The image below shows the posture of the right hand attached on our object.

Use collider¶
This is the collider that will trigger with the cloth.
From the MAGES menu select the option CreatePrefab/Use Action Collider

In this case we add a dust textured model to represent the dust particles on top of the Sponza model.
Note
Remember to add a trigger collider to your prefab
Below you can see the final use collider.

Hologram¶
To visualize the Action we will include an animated hologram indicating the interactable prefab and how to use it. This hologram will visualize the cloth hovering on top of the sponza. Below you can see the holographic cloth.

Save prefabs and final configuration¶
Save the prefabs in the Resources folder. It is recommended to keep the prefabs in folders according to the scenegraph structure. In this case we will save the interactable, use collider and hologram prefab at Resources/Lesson1/Stage1/Action1 folder.

Now we have to link the use collider with the interactable prefab.
Navigate to our use collider (dust prefab) and from the UseColliderPrefabConstructor
you need to set the PrefabsUsed
variable to 1
.
Then, drag and drop the interactable prefab (cloth) at the Element 0 position.
Additionally, set the StayTime
variable to the amount of time that the cloth needs to stay in contact with the use collider.
In this case, we set it to 2
seconds, meaning that we have to keep the cloth in contact with the collider for 2 seconds to Perform.

Action Script¶
The script below initializes the use prefab.
using MAGES.ActionPrototypes;
public class CleanSponzaAction : UseAction
{
public override void Initialize()
{
SetUsePrefab("Lesson1/Stage1/Action1/Cloth", "Lesson1/Stage1/Action1/Dust");
SetHoloObject("Lesson1/Stage1/Action1/ClothHologram");
base.Initialize();
}
}