Automatic Stubbing is a feature of the 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.
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 Playable Plugin 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
- Navigate to the Code section, and the Stubs tab in the Playable Plugin Unity plugin window.
- 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
- If you need to stub another library, youll need to enter its 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 youve entered the details of the library you want to stub, click the “Generate Stub” button and its details will appear in the list of stubs above. From that list, you can easily enable or disable the stub by toggling the checkbox.
- 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.