Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

How to Add an Interactive Rive Mascot to an Electron Desktop App

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: How to Add an Interactive Rive Mascot to an Electron Desktop App, with Charmotion demo characters

Load a .riv file in a transparent Electron window, then pass mood changes from the main process to the renderer through a preload script and contextBridge. Electron's transparent windows cannot be clicked through, so the window should be only as large as the mascot. Export the file from a paid Rive plan.

Key takeaways

  • An Electron app plays the Rive file in a renderer window, because the main process has no canvas to draw on.
  • A preload script should expose one narrow mood callback through contextBridge, never the whole ipcRenderer module.
  • Electron's transparent windows cannot be clicked through, so keep the mascot window small.
  • Rive's free plan cannot export .riv files for an app, so a paid seat is needed before you ship.

Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.

What do you need before you add the mascot?

This guide shows how to add an animated Rive mascot to an Electron desktop app: a small, transparent, always-visible window that plays a character and changes its mood from the app's own state. It assumes you already have an Electron project running.

You need four things:

  • An Electron app with a main process and a renderer page. The renderer is ordinary Chromium, so any web framework that runs in it works.
  • A .riv file. Runtimes load .riv files. The .rev format is for backups and editing, and runtimes cannot load it, so keep it as your source file.
  • A paid Rive plan for the export. Files created on the free plan cannot be exported as .riv for use in an app. Rive lists Cadet at $9 per seat per month (as of December 2026), and Cadet exports .riv files without the splash screen.
  • The Rive web runtime. Rive's React wrapper, @rive-app/react-canvas, is the option Rive recommends for most apps unless a WebGL renderer is needed.

For background on how states and inputs work, read Rive state machines.

Where does the .riv file come from?

Design the mascot in the Rive editor, or start from a character image. A .riv file bundles the artboards, animations, state machines and data binding settings, so the app only has to load that one file. Write down the state machine name and the input or property names before you build the app, so developers and designers use the same strings.

Plan the moods your app needs before you animate them. A typical set is idle, happy for a completed action, sad for a failed one, loading while work runs and attention for a reminder. Each mood should be a state the file can enter from any other state.

If you do not have a motion designer, Charmotion can produce this file from one finished, front-facing character image. You choose the animations (idle is always included, and launch, happy, wave and loading are preselected). The output is one .riv file with CharacterViewModelMachine (a number property named mood), CharacterStateMachine (a number input named mood) and LaunchStateMachine when launch is picked. Charmotion also includes paste-ready React code for the file. Start at /app/create and check plan details on the pricing page.

How do you set up the transparent mascot window?

Electron creates the mascot in its own BrowserWindow. Two options do most of the work. transparent: true makes the window fully transparent, and frame: false removes the title bar so only the character shows. alwaysOnTop keeps it above other windows, which suits a companion that stays on screen.

const path = require('path')
const { app, BrowserWindow } = require('electron')

function createMascotWindow() {
  const mascot = new BrowserWindow({
    width: 240,
    height: 240,
    transparent: true,
    frame: false,
    alwaysOnTop: true,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })
  mascot.setOpacity(1.0)
  mascot.loadFile('mascot.html')
  return mascot
}

app.whenReady().then(() => {
  const mascot = createMascotWindow()
})

Electron's custom window styles guide notes that a transparent window cannot be clicked through in its transparent area. The mascot window therefore takes clicks across its whole rectangle, so size it to the character instead of leaving a large empty canvas. setOpacity takes a number from 0.0 (fully transparent) to 1.0 (fully opaque), which is useful for fading the mascot in or dimming it while the app is busy.

How do you send mood changes safely with a preload script?

The renderer page should not have Node access. Use a preload script to expose one narrow function, and let the main process push mood numbers to it. Electron's IPC tutorial uses this pattern: the preload script calls contextBridge.exposeInMainWorld under a named API object.

const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('mascot', {
  onMood: (callback) => ipcRenderer.on('mascot:mood', (_event, mood) => callback(mood))
})

Do not pass the whole ipcRenderer module across the bridge. The contextBridge API page warns that the receiving side gets an empty object. The version above passes only the mood value, which keeps the surface small and easy to audit.

In the main process, send a mood whenever app state changes:

function setMascotMood(mascot, mood) {
  mascot.webContents.send('mascot:mood', mood)
}

// A sync job starts, then finishes
setMascotMood(mascot, 5) // loading
setMascotMood(mascot, 1) // happy

Keep the mood numbers in one shared constants file, so the main process and the renderer agree on what each number means.

How do you play the Rive file in the renderer?

In the renderer, load the file with the Rive React runtime and start the state machine by name. The state machine name must match the name inside your .riv file. For a Charmotion file, that is CharacterStateMachine.

import { useRive } from '@rive-app/react-canvas'

export default function Mascot() {
  const { RiveComponent } = useRive({
    src: 'mascot.riv',
    stateMachines: 'CharacterStateMachine',
    autoplay: true
  })

  return <RiveComponent />
}

The canvas takes its size from the mascot window created in the previous section, so the component needs no sizing props. Then connect the preload API: when the renderer receives a mood number from window.mascot, set the mood input that your runtime version documents. Check the current input or data binding names in Rive's runtime docs before you copy an example from an older article, because the older useStateMachineInput hook is marked deprecated in favour of the newer data binding hooks.

Charmotion files use the same wiring. The mood input is a number, so pass the mood value straight through, and the file blends from one mood to the next.

What breaks a transparent Electron mascot?

Most problems come from the window, not the animation. Check these before release:

  • Clicks on empty space. A transparent window does not pass clicks through its transparent area, as Electron's window styles guide notes. Make the window the size of the character.
  • Platform differences. Electron's docs describe transparency in general terms. Test the mascot on each operating system you ship, and on a lower-end machine, before release.
  • Too many instances. Create one Rive instance per mascot window. Changing mood should update the existing state machine, not rebuild the canvas.
  • Packaging. The Distribution section of Electron's docs covers packaging and shipping. Follow it for each platform, and keep the .riv file inside the packaged app so it loads without a network call.

The state design is the part most teams underestimate. Keep the number of moods small, name them by what the user sees, and read the input design in Rive state machine inputs. For a similar transparent setup on a streaming setup, see adding an animated mascot overlay to OBS.

How to add an animated Rive mascot to an Electron desktop app

  1. Export the .riv file. In the Rive editor on a paid plan, export the mascot as a .riv file with its state machine. Keep the .rev source file for edits, since runtimes cannot load it.
  2. Create a transparent window. In the main process, create a BrowserWindow with transparent set to true and frame set to false, sized to the character.
  3. Expose a narrow preload API. In the preload script, use contextBridge.exposeInMainWorld to expose one onMood callback. Do not expose the whole ipcRenderer module.
  4. Send mood numbers from the main process. When app state changes, call webContents.send on the mascot window with a mood number, using one shared list of mood numbers.
  5. Play the file in the renderer. Load the .riv file with the Rive React runtime, start the state machine by name, and set the mood input when the preload callback fires.

Frequently asked questions

Does the Electron main process draw the Rive animation?

No. The main process has no canvas, so the .riv file plays in a renderer page inside a BrowserWindow. The main process only sends small messages, such as a mood number, to that window. Keep the app logic in the main process and the drawing in the renderer, and avoid moving large data across the bridge.

Which mood numbers does a Charmotion file use?

Idle is 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. The mood input is a number, and moods blend into each other. Charmotion characters have no one-shot triggers, so show a success with happy and an error with sad.

Can the Rive mascot run offline in an Electron app?

Yes, if the .riv file and the runtime ship inside the app. Load the file from the app's own files rather than a remote URL, so the mascot does not wait on a network request at startup. The animation itself does not need a connection once it is loaded.

Do I need a paid Rive plan for a desktop app?

Yes, for the export. Files created on the free plan cannot be exported as .riv for use in an app, so buy a seat before you ship. Rive lists Cadet at $9 per seat per month as of December 2026. Plan details change, so check rive.app/pricing or read /guides/is-rive-free-pricing.

Sources

Related guides