Skip to main content

Automatic Stubbing

Automatic Stubbing is a feature of the Luna Playable plugin for Unity that allows you to automatically stub libraries that are not essential to your playable but are included in your Unity project. This feature is especially useful for disabling third-party SDKs that provide non-gameplay functionality like ads, analytics and error reporting without having to edit your code or change your project.

Why not check out our blog post on how the stubber works!

When to use it#

If your project contains a plugin, SDK or library that you know will not be essential for your playable, it may be necessary to remove that library and any references to it to either successfully execute the Luna Playable build process or reduce the size of your final build. It is recommended that you use the Automatic Stubbing feature to accomplish this.

In addition to specifying namespaces to be stubbed manually, we have also included a number of commonly used SDK stubs that you can enable easily by selecting them in the plugin editor window.

How it works#

The Automatic Stubbing feature takes a namespace or path and locates all assemblies belonging to that namespace or at the specified path, it will then fetch all associated public classes, enumerations and structs. With the collected information, the plugin generates all types and methods that can be used in user scripts and implements them as stubs with empty bodies, except when the method has a non-void return type in which case it will generate a default value.

The plugin saves generated stubs in a Stubs directory in the project root directory, scripts located here will be organised by namespace and class.

How to use it#

  1. Navigate to the Code section, and the Stubs tab in the Luna Playable Unity plugin window.luna-ui-code
  2. If you intend to stub one of the commonly used SDKs listed, simply toggle the checkbox to the left of the name of the SDK you want to stub. You can enable as many of these as you wish. The plugin automatically adds folders with this SDK to excludes to avoid conflicts when you export your Luna build
  3. If you need to stub another library, you’ll need to enter it’s namespace and list any specific classes you want to stub. If you want to stub all public classes within a namespace, leave the classes field empty. You can also provide a human-readable name for each namespace to help you and your team members identify it easily. Once you’ve entered the details of the library you want to stub, click the “Generate Stub” button and it’s details will appear in the list of stubs above. From that list, you can easily enable or disable the stub by toggling the checkbox.luna-ui-code
  4. If you enable a stub for a custom namespace, you will need to ensure that Luna excludes the original scripts during the export process to avoid errors. You can accomplish this by adding the directory to list of Force Excluded C# files in the Source Code section of the plugin. For more details on the Force Exclusion process, read our documentation on Excluding C# code from compilation.
If you attempt to add a stub for a namespace that does not exist in your project, the plugin will throw an exception and the library will not be added to the list of stubs. Make sure to check the console in the Unity Editor for errors when attempting to add a stub.