Creating Custom Actions

In this guide you will learn how to set up your very own custom actions, by recreating the "Move GameObject below to Origin" Action.

In this guide you will learn how to set up your very own custom actions, by recreating the "Move GameObject below to Origin" Action.

Step-by-step guide

Follow these steps to learn how to create your first custom action. From there, you are all set to extend EpicMenu with all your custom code!

  1. Navigate to the EpicMenu Settings Window by going to Window > HotTotemAssets > EpicMenu Settings

    drawing
  2. Next, select your menu of choice in the dropdown
  3. Click on the slot you want to assign your new action to, and select "Custom Actions > Create New..."

    drawing
  4. A box will pop up and ask you for a name. Please note this does NOT have to be a valid file name, that will be automatically generated. You can name the action with a meaningfull name so you lateron know exactly what it does just by looking at the name. In our demo case, we will name it "Move GameObject below to Origin". Click "Done" and your Editor of choice will popup and present you a template to create your custom Action.
Do **NOT** remove the comments before the Class definition, and do **NOT RENAME** the class or the Action-method.
  1. You will see the class comes with a predefined Action-Method. This is where you can populate your code, and this Action will be executed when selecting it via the EpicMenu.
  2. The Action-Method comes with an argument :
    public override void Action(Ray sceneViewToEpicMenuCenterRay)
    {
        //Add your custom code here.
            //It will be executed upon selecting a shortcut via the EpicMenu
    }

The argument is a Ray, that goes from the Camera of the scene view towards to center of the EpicMenu. You can make use of this e.g. to detect an object below the Center and do something with it. In this case, we will move it back to the Origin.

  1. We will do a simple Raycast using the provided ray, and if it collides with an object below, it will be moved to the origin:
    public override void Action(Ray sceneViewToEpicMenuCenterRay)
    {
        RaycastHit hitInfo;
        var hasHit = Physics.Raycast(sceneViewToEpicMenuCenterRay, out hitInfo);
        if (hasHit)
        {
            var hitObj = hitInfo.collider.gameObject;
            hitObj.transform.position = new Vector3(0, 0, 0);
        }
    }
  1. That's it, your very first custom action. Save the file, and go back to Unity, you will see the action is already assigned to the Actionslot selected before. Go ahead and try it out!

    drawing