Your first SKSE plugin in C++

Your adventure begins today.

In this tutorial, you will:

  • Setup the tools required to create SKSE plugins
  • Download SKSE plugin template
  • Configure the SKSE plugin
  • Build the SKSE plugin
  • Run the SKSE plugin in Skyrim
  • Code review

This tutorial does not require any C++ knowledge.

Requirements

  • Skyrim
    • Special Edition or Anniversary Edition or VR
    • Must be from Steam or GOG

      At this time, only the Steam and GOG versions of Skyrim are supported by SKSE.

  • Skyrim Script Extender (SKSE)
    • Must be the correct version for your version of Skyrim
  • Address Library for SKSE Plugins
    • Must be the correct version for your version of Skyrim

Setup the tools required to create SKSE plugins

You will need:

  1. Visual Studio 2022 (required to compile C++ SKSE plugins)
  2. vcpkg (required to download C++ libraries)

Visual Studio 2022

Desktop development with C++

vcpkg

  • Download or clone GitHub repository https://github.com/microsoft/vcpkg

  • In the downloaded vcpkg folder, double-click bootstrap-vcpkg.bat to run it

    A command prompt may briefly open and then close while vcpkg is bootstrapped

  • Open the Start menu, type ‘environment’, and choose ‘Edit environment variables for your account

    Edit environment varioables for your account

  • Click New to create a new environment variable

  • Give it the name VCPKG_ROOT and the value should be the path to the vcpkg folder you downloaded:

    Setting the VCPKG_ROOT environment variable

Download SKSE plugin template

  • Visit https://github.com/SkyrimDev/HelloWorld-using-CommonLibSSE-NG

  • Open the Code drop-down:

    GitHub project Code drop-down

    The URL in the screenshot above may not match the template you are downloading.

  • From there, you can Download ZIP, Open with Visual Studio, Open with GitHub Desktop, or copy the git URL to clone the repository manually.

Use this template (Optional)

If you plan on creating a new project of your own from this template, you can use the Use a new template drop-down to quickly create a new GitHub repository using this template as a starting point.

Use this template - Create a new repository

Configure the SKSE plugin

This SKSE plugin template can be configured to automatically copy the compiled SKSE plugin .dll into your Skyrim Data folder or the mods folder used by your mod manager (e.g. Mod Organizer 2 or Vortex).

Mods folder

If you are using a mod manager, you can configure this template to output the compiled .dll to your mods folder.

  1. Find your mods folder
  2. Configure the SKYRIM_MODS_FOLDER environment variable

To find your mods folder, open your mod manager and find the mods path in the settings.

Mod Organizer 2:

Mod Organizer 2 - Mods folder path

Vortex:

Vorted - Mods folder path

Once you have the path of your mods folder:

  • open the Start menu, type ‘environment’, and choose ‘Edit environment variables for your account

    Edit environment varioables for your account

  • Click New to create a new environment variable

  • Give it the name SKYRIM_MODS_FOLDER and the value should be the path to your mods folder:

    Setting the SKYRIM_MODS_FOLDER environment variable

Data folder

To output the compiled SKSE plugin directly into your Skyrim folder:

  1. Find your Skyrim game folder
  2. Configure the SKYRIM_FOLDER environment variable

To find your Skyrim game folder, open your Skyrim game in Steam or GOG.

Steam:

Click the “cog wheel”, then choose “Manage” > “Browse Local Files”.

Steam - Manage - Browse Local Files

GOG:

Click the settings button, then choose “Manage installation” > “Show folder”.

GOG - Manage Installation - Show Folder

Once you have the path of your Skyrim game folder:

  • open the Start menu, type ‘environment’, and choose ‘Edit environment variables for your account

    Edit environment varioables for your account

  • Click New to create a new environment variable

  • Give it the name SKYRIM_FOLDER and the value should be the path to your Skyrim game folder:

    Setting the SKYRIM_MODS_FOLDER environment variable

View the README of the sample project for any additionally required configuration

Build the SKSE plugin

The screenshots in this section are generic and might not exactly match what you will see for your SKSE template.

If you set any environment variables, be sure to close all text editors and GitHub Desktop. You most close and re-open programs after you set environment variables.

Open the folder of the template you downloaded in a C++ code editor.

One of the easiest ways of doing this is to:

  • Right-click the folder of the template project in Windows File Explorer
  • From the right-click context menu, choose “Open with <your preferred editor>

    Windows File Explorer Right-Click Context Menu Text Editor Open Options

    In Windows 11, you may need to choose “Show more options” for these options to become available

  • Alternatively, open your C++ code editor of choice and open the template folder from there (the steps will be specific to your editor application).

Once you open the template folder, the steps will be different based on your C++ code editor.

Visual Studio

Once you open the template folder in Visual Studio, it will automatically detect the project is a CMake project and display the CMake page.

Visual Studio CMake Splash Screen

At the same time, Visual Studio will automatically run a CMake configure for your project. You should see the Output window open and display the CMake output.

Visual Studio performing CMake configure

If you configured the project correctly, the Output should contain the text “SKSE plugin output folder: <path you configured earlier>“

After you see “CMake generation finished.”, you are ready to compile your SKSE plugin.

Press F7 or use the “Build” > “Build all” menu option.

Visual Studio - Build - Buila All

If everything compiles successfully, you should see “Build All succeeded”

Visual Studio - Build All succeeded

Other

For other editors, reference their documentation for building CMake projects.

Run the SKSE plugin in Skyrim

Once your SKSE plugin has been successfully built, a .dll will be generated.

This is your SKSE plugin.

If you followed the steps to configure the SSKE plugin template, the .dll should now reside in either:

  • your Data folder (in Data\SKSE\Plugins\)

- or -

  • in your mods folder (in <mods>\<Template name>\SKSE\Plugins\)

You are ready to run Skyrim.

Be sure to run Skyrim via SKSE by running skse64_loader.exe directly -or- by running SKSE from your mod manager (e.g. Mod Organizer 2 or Vortex)

See the SKSE plugin in action

The Hello, world! template prints a message to the Skyrim ~ game console.

This can be viewed by launching the game and, at the Main Menu, press the ~ or ` key to open the console.

You should see the message: “Hello, world!”

Skyrim Main Menu Console Hello world

Code review

Plugin.cpp

SKSEPluginLoad(const SKSE::LoadInterface *skse) {
    SKSE::Init(skse);

    // This example prints "Hello, world!" to the Skyrim ~ console.
    // To view it, open the ~ console from the Skyrim Main Menu.
    SKSE::GetMessagingInterface()->RegisterListener([](SKSE::MessagingInterface::Message *message) {
        if (message->type == SKSE::MessagingInterface::kDataLoaded)
            RE::ConsoleLog::GetSingleton()->Print("Hello, world!");
    });

    return true;
}

CMakeLists.txt

# Set your project name. This will be the name of your SKSE .dll file.
project(HelloWorld VERSION 0.0.1 LANGUAGES CXX)

Updated: