This folder contains the native Windows plugin for unity-webview, using Microsoft WebView2 (Edge Chromium).
- Windows 10 or later
- Visual Studio 2019 or 2022 (or newer) with "Desktop development with C++"
- WebView2 Runtime (usually preinstalled on Windows 11 / recent Windows 10)
The project requires the WebView2 SDK headers and libraries. Please perform one of the following methods before opening Visual Studio to build.
Method A – Restore via Script (Recommended)
Open PowerShell and navigate to the plugins/Windows folder, then run:
.\restore_webview2_sdk.ps1The script will automatically download nuget.exe (if not installed) and restore Microsoft.Web.WebView2, generating the packages\Microsoft.Web.WebView2.1.0.3800.47\ folder which contains build\native\include\WebView2.h and other necessary files.
Method B – Manual NuGet Restore
If you have the NuGet CLI installed, open Command Prompt or Developer PowerShell, navigate to plugins/Windows, and run:
nuget install Microsoft.Web.WebView2 -Version 1.0.3800.47 -OutputDirectory packagesMethod C – Manual SDK Download
- Go to NuGet: Microsoft.Web.WebView2, download the 1.0.3800.47
.nupkgfile, rename its extension to.zip, and extract it. - Place the extracted
build\native\includeandbuild\native\x64(usebuild\native\x86for 32-bit) in the appropriate paths, or modify the Include/Library directories inWebViewPlugin.vcxprojto point to your custom location.
- Ensure you have completed "1. Get the WebView2 SDK" above, so that files like
packages\Microsoft.Web.WebView2.1.0.3800.47\build\native\include\WebView2.hexist. - Double-click to open
WebViewPlugin.sln(or open this solution file via Visual Studio). - Build 64-bit (x64):
- Select x64 from the platform dropdown at the top, and set the configuration to Release.
- Click "Build → Build Solution".
- The output DLL will be located at:
plugins\Windows\bin\x64\Release\WebView.dll
- Build 32-bit (Win32 / x86):
- Select Win32 from the platform dropdown at the top, and set the configuration to Release.
- Click "Build → Build Solution".
- The output DLL will be located at:
plugins\Windows\bin\Win32\Release\WebView.dll
Command-line build (Optional):
cd <ProjectRoot>\plugins\Windows
msbuild WebViewPlugin.sln /p:Configuration=Release /p:Platform=x64
msbuild WebViewPlugin.sln /p:Configuration=Release /p:Platform=Win32Copy the built WebView.dll into the corresponding directory in your Unity project:
- 64-bit (x64): Copy to
Assets/Plugins/x64/WebView.dll - 32-bit (Win32): Copy to
Assets/Plugins/x86/WebView.dll
Unity will load it on Windows Editor and Windows Standalone builds. The WebView2 Runtime must be installed on the machine where the built game runs (see the main README for distribution notes).
The plugin has built-in OutputDebugString logging to verify if mouse/keyboard events reach the DLL and what the target window is.
- Compile Time: Logging is controlled by
WEBVIEW_DEBUGat the top ofWebViewPlugin.cpp(default is 0, which means disabled). Change it to#define WEBVIEW_DEBUG 1and rebuild to enable it. - View Logs:
- DebugView (Recommended): Download Sysinternals DebugView. Run it as Administrator, check Capture → Capture Global Win32 in the menu, then run Unity and the sample scene. When you click on the WebView, you should see lines starting with
[WebView2](e.g.,SendMouseEvent called,MOUSE recv,targetClass=...). - Visual Studio: Run the Unity project using "Start Debugging" (or attach to the Unity process), and select "Debug" in the Output window to see the same logs.
- DebugView (Recommended): Download Sysinternals DebugView. Run it as Administrator, check Capture → Capture Global Win32 in the menu, then run Unity and the sample scene. When you click on the WebView, you should see lines starting with
The logs will print: whether C# called SendMouseEvent/SendKeyEvent, if the STA thread received it, the handles for hwnd/child/target, the class name of the target window (e.g., Chrome_WidgetWin_1 or UnityWebView2Window), and the converted coordinates. This information is crucial for determining if input forwarding is working correctly.