NjConsole Docs

πŸ’» 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 define NJCONSOLE_DISABLE to strip out the console completely. See next section for more info.

βœ‚οΈ Disable / Strip NjConsole for Production

βœ… Benefits of Stripping

🧩 How It Works

βœ‚οΈ How to Disable NjConsole

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();
    }
}

NjConsole doc home