# Combined Action¶

The Combined Action does not include any new VR behavior, it is a way to include multiple Actions in the same script. Combined Actions are useful in situations where we want to implement sequential tasks but incorporate them into a single entity.

In this example, we will convert the UseAction and the RemoveAction from the previous tutorials into a CombinedAction. As a result, in this Action the user would be asked to clean the sponza with a cloth (UseAction) and then remove the jar using his hand (RemoveAction).

## Action Script¶

The script below configures the Combined Action.

using MAGES.ActionPrototypes;
public class UseAndCleanAction : CombinedAction
{
public override void Initialize()
{
//Use sub-Action
cleanSponzaAction.SetUsePrefab("Lesson1/Stage1/Action1/Cloth", "Lesson1/Stage1/Action1/Dust");
cleanSponzaAction.SetHoloObject("Lesson1/Stage1/Action1/ClothHologram");
//-------------------------------------------------------------------------------------------

//Remove sub-Action
removeJarAction.SetRemovePrefab("Lesson1/Stage1/Action1/JarRemove");
removeJarAction.SetHoloObject("Lesson1/Stage1/Action1/RemoveWithHandHologram");

InsertIActions(cleanSponzaAction, removeJarAction);

base.Initialize();
}

//Example of Perform() in CombinedAction
public override void Perform()
{
//This method will invoke after all the sub-Action will perform
}
}


## Combined Action explanation¶

As you can see, only the syntax of the Action script has changed while the functions and methodology remains the same.

In this example we developed two sub-Actions: 1) a UseAction where the user needs to clean the sponza model and 2) a RemoveAction where the user is asked to remove the jar.

Note

The sub-Actions will be initialized sequentially, meaning that the Initialize() of the UseAction will be called first. When the user completes the Action, the Initialize() of the RemoveAction will be called. Finally, when all the sub-Actions are performed, the Perform() of the CombinedAction will be called as well.

The method InsertIActions() sets the sequence of the sub-Actions. For example if we set the arguments like this: InsertIActions(removeJarAction, cleanSponzaAction); the sub-Actions will be initialized in the reverse order (first the remove then the use). This function is mandatory for the CombinedAction to work properly.

Additionally, you can see that we manually added the sub-Actions as components in the Action’s gameObject.

RemoveAction removeJarAction = gameObject.AddComponent<RemoveAction>();


To access each sub-Action’s methods use the sub-Action variable.

removeJarAction.SetRemovePrefab("Lesson1/Stage1/Action1/JarRemove");


To access the Perform() and the Undo() of a sub-Action use the SetPerformAction() and the SetUndoAction()

cleanSponzaAction.SetPerformAction(()=>Spawn("Lesson1/Stage1/Action1/Sparkling"));


This example will spawn the Sparkling prefab after performing the cleanSponzaAction sub-Action.

Similarly, we save the prefabs related to this Action in a single folder, in this case “Lesson1/Stage1/Action1”