Restricting an Action to a Specific Class
Depending on the work you need your Scripted Actions to carry out, you may want them to appear in the contextual menu only for specific types of objects.
For example, say you create a Scripted Action that changes Materials on selected Actors. In this case, you might want that action to only appear when the user right-clicks on Static Mesh Actors, but not when the user right-clicks on Light Actors or Blueprints.
The AssetActionUtility and ActorAssetUtility base classes both offer a built-in function named GetSupportedClass. This function determines the class of objects that need to be selected in order for the Scripted Actions in your Blueprint class to appear in the contextual menu. Each time the user right-clicks on a set of Assets or Actors, this function is called to get the class type supported by the AssetActionUtility or ActorAssetUtility class. If it returns a class type, that return value is compared against the set of Assets or Actors that the user currently has selected. If at least one of those Assets or Actors has a class that matches the class returned by GetSupportedClass, then the Scripted Actions will appear in the contextual menu. By default, the GetSupportedClass function returns nothing. This makes all Scripted Actions appear regardless of the classes of Assets or Actors you have selected.
If you want to change this default behavior, you can override the GetSupportedClass function in your class to return a specific class type:
For example, this implementation within an ActorAssetUtility returns the StaticMeshActor class, so the Scripted Actions in this class will appear in the contextual menu when the user has at least one Static Mesh Actor selected at the time they open the contextual menu:
But the Scripted Actions does not appear when the user only has other kinds of Actors selected:
If you have multiple Assets or Actors selected, the behavior is permissive: as long as at least one of the selected items matches the class returned by GetSupportedClass, your Scripted Actions will appear in the contextual menu. Even if you override GetSupportedClass to restrict the classes handled by your actions, you're not guaranteed to only have instances of that class selected when the action gets run. Keep this in mind when you implement your Blueprint graphs.