Skip to content

Latest commit

ย 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

react-godot-bridge

npm version npm downloads license GitHub stars

Bidirectional, event-driven bridge between a React / Next.js app and a Godot 4 WebAssembly game running inside an <iframe>.

Designed to feel like Socket.io โ€” you just call emit("event") and on("event"). The library handles the iframe, postMessage, and JavaScriptBridge complexity underneath.

react-godot-bridge demo


Repository Structure

react-godot-bridge/
  addons/           โ† Godot plugin (Asset Library & manual install)
  npm/              โ† npm package source  (published as "react-godot-bridge")
  example/          โ† Next.js demo app

React / Next.js โ€” npm package

npm install react-godot-bridge
import { GodotBridgeProvider, GodotFrame, useGodot } from 'react-godot-bridge';

// Wrap your layout
<GodotBridgeProvider appKey={process.env.NEXT_PUBLIC_BRIDGE_KEY ?? ''}>
  <GodotFrame src="/game/index.html" className="w-full h-screen" />
  <HUD />
</GodotBridgeProvider>

// Use anywhere inside the Provider
const { emit, on } = useGodot();
emit('jump', { height: 2 });
const unsub = on('player_died', (p) => setScore(p.score as number));

See npm/README.md for full API docs.


Godot โ€” Plugin

Option A โ€” Godot Asset Library (recommended) Search ReactBridge in the AssetLib tab inside the Godot editor and click Install.

Option B โ€” Manual Copy addons/react_bridge/ from this repo into your Godot project root, then add the autoload in Project Settings:

[autoload]
ReactBridge="*res://addons/react_bridge/ReactBridge.gd"
# Receive from React
func _ready():
    ReactBridge.on_react_event.connect(_on_event)

func _on_event(event: String, data: Dictionary):
    if event == "jump":
        $Player.position.y += data.get("height", 1.0)

# Send to React
ReactBridge.emit_to_react("player_died", { "score": 1500 })

See addons/react_bridge/README.md for full docs.


How It Works

React                              Godot (iframe)
โ”€โ”€โ”€โ”€โ”€โ”€                             โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
emit("jump", { height: 2 })
  โ†’ postMessage(envelope)    โ†’     ReactBridge._on_message()
                                     on_react_event.emit("jump", data)
                                       $Player.position.y += data.height
                                     ReactBridge.emit_to_react("pong", {...})
  on("pong", cb) โ†           โ†       window.parent.postMessage(envelope)

All messages use a standard JSON envelope:

{
  "event": "jump",
  "payload": { "height": 2 },
  "metadata": { "secret": "APP_KEY", "timestamp": 1711910000 }
}

Links

About

๐ŸŽฎ Bidirectional, event-driven bridge between React and a Godot WebAssembly game in an iframe

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages