๐ป Build customization
๐ง Dynamically Configure Console Features During Build
The example below disables the Hierarchy and Object Inspector panels for WebGL builds.
public class NjConsoleSettingsBuildProcessor : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var settings = ConsoleSettings.Get();
var platform = report.summary.platform;
settings.inPlayerObjectInspector = platform != BuildTarget.WebGL;
settings.inPlayerHierarchyPanel = platform != BuildTarget.WebGL;
}
}
โ ๏ธ Note: In production builds, a determined attacker could still enable console features via memory hacking.
For best security, use compile defineNJCONSOLE_DISABLEto strip out the console completely. See next section for more info.
โ๏ธ Disable / Strip NjConsole for Production
โ Benefits of Stripping
- ๐ง Reduces memory usage and final build size.
- ๐ Prevents malicious users from reverse engineering to access NjConsole UI, cheat options, etc.
- โ Highly recommended for production releases.
๐งฉ How It Works
- โ๏ธ NjConsole scripts are conditionally stripped using
#if !NJCONSOLE_DISABLE. - ๐งฑ Most interfaces and key classes are safely stubbed, so your project continues to compile without errors.
- โ Certain advanced APIs are completely stripped and must be wrapped manually using
#if !NJCONSOLE_DISABLE. - ๐ You should also wrap your own cheat/debug logic with
#if !NJCONSOLE_DISABLEto ensure itโs fully stripped from production builds. - ๐ Log history is still collected in the background โ useful for crash reports or customer service diagnostics.
โ๏ธ How to Disable NjConsole
- ๐๏ธ๏ธ UI Method: Go to Project Settings > NjConsole > Disable NjConsole
- โ๏ธ Manual Define: Add
NJCONSOLE_DISABLEin Player Settings > Scripting Define Symbols. - ๐งโ๐ป Code/API Method: Call
ConsoleEditorSettings.AddDefineSymbolToDisableConsole()
Example below disables NjConsole in release builds, and attempts to reenable it after the build.
using Ninjadini.Console.Editor;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class NjConsoleBuildDisableProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder => -1000;
public void OnPreprocessBuild(BuildReport report)
{
var isDevelopmentBuild = (report.summary.options & BuildOptions.Development) != 0;
if (isDevelopmentBuild) return;
// ^ Have your own conditional logic here. In this example, we only disable NjConsole in release (non-debug) builds.
ConsoleEditorSettings.AddDefineSymbolToDisableConsole();
}
public void OnPostprocessBuild(BuildReport report)
{
// Reenable NjConsole.
// Unfortunately, if the build failed, this code will not execute and you'll need to manually turn it on from Project Settings > NjConsole > Disable.
// This code is not needed if you are using a build box where you revert the changes after build.
ConsoleEditorSettings.RemoveDefineSymbolAndEnableConsole();
}
}