Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

Write me a MelonLoader mod that makes a UI menu that can work on any Unity game

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-2025-04-14’s answer.
  1. User

    Write me a MelonLoader mod that makes a UI menu that can work on any Unity game

  2. Assistant

    Of course! I'll walk you through creating a basic MelonLoader mod that adds a simple UI menu that can work across most Unity games.

    —

    First, some important notes:

    • MelonLoader is a mod loader for Unity games.
    • We'll use UnityEngine.UI for the UI elements.
    • Since not all games have UnityEngine.UI loaded, we might need to dynamically load it or fallback to IMGUI (OnGUI).
    • For maximum compatibility, we'll use Unity's built-in OnGUI system (IMGUI) for this example.

    —

    Here's a basic MelonLoader mod that creates a simple toggleable UI menu:

    📄 File: SimpleUIMenuMod.cs

    using MelonLoader;
    using UnityEngine;
    
    [assembly: MelonInfo(typeof(SimpleUIMenuMod.SimpleUIMenu), "Simple UI Menu", "1.0.0", "YourName")]
    [assembly: MelonGame] // No specific game, works on any
    
    namespace SimpleUIMenuMod
    {
        public class SimpleUIMenu : MelonMod
        {
            private bool showMenu = false;
            private Rect windowRect = new Rect(20, 20, 300, 400);
    
            public override void OnUpdate()
            {
                // Toggle menu with F1 key
                if (Input.GetKeyDown(KeyCode.F1))
                {
                    showMenu = !showMenu;
                }
            }
    
            public override void OnGUI()
            {
                if (showMenu)
                {
                    windowRect = GUI.Window(0, windowRect, DrawMenuWindow, "Simple UI Menu");
                }
            }
    
            private void DrawMenuWindow(int windowID)
            {
                GUILayout.BeginVertical();
    
                GUILayout.Label("Hello from MelonLoader!");
                if (GUILayout.Button("Button 1"))
                {
                    MelonLogger.Msg("Button 1 Pressed!");
                }
    
                if (GUILayout.Button("Button 2"))
                {
                    MelonLogger.Msg("Button 2 Pressed!");
                }
    
                GUILayout.Label("Slider Example:");
                float sliderValue = 0.5f;
                sliderValue = GUILayout.HorizontalSlider(sliderValue, 0f, 1f);
    
                GUILayout.Label($"Slider Value: {sliderValue:F2}");
    
                GUILayout.EndVertical();
    
                // Allow window dragging
                GUI.DragWindow(new Rect(0, 0, 10000, 20));
            }
        }
    }
    

    —

    🛠 How this works:

    • Press F1 to toggle the menu on/off.
    • A draggable window appears with buttons and a slider.
    • Button clicks are logged to the MelonLoader console.

    —

    📦 How to build:

    1. Create a new Class Library (.NET Framework 4.7.2) project in Visual Studio.
    2. Add references to:
      • MelonLoader.dll
      • UnityEngine.dll
    3. Paste the code above into your main class.
    4. Build the DLL.
    5. Place the compiled DLL into the Mods folder of your MelonLoader-installed game.

    —

    ✨ Bonus: If you want a fancier UI (with UnityEngine.UI or TMPro), you would need to check if the game has those libraries loaded, and dynamically create Canvas, Buttons, etc. But IMGUI (OnGUI) is the safest for "any Unity game" compatibility.

    —

    Would you like me to also show you an advanced version with tabs, toggles, and saving settings? 🚀
    (If yes, just say so!)

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.