Website | Code Examples | Discord | Web Demo
Safe, low-latency and fast sandbox for the Godot game engine.
Godot Sandbox allows Godot creators to implement safe modding support, such that they can pass around programs built by other players, knowing that restricted programs cannot harm other players. All Godot platforms are supported.
-
Automatic (Recommended): Download the plugin from the official Godot Asset Store using the AssetLib tab in Godot by searching for Godot Sandbox.
-
Manual: Download the latest github release and move only the addons folder into your project addons folder.
- Modding API
- You can implement a modding API for your game. This API can then be used by other players to extend your game, in a safe manner.
- Put restrictions on resources, classes and objects to say what is accessible inside the sandbox.
- Build once, run everywhere
- You can publish your game for all mobile and console platforms, without paying a performance penalty. It's not going to be laggy on some platforms, which is a risk with solutions that are only fast when JIT is available.
- High-performance
- You can use this extension as a way to write higher performance code than GDScript permits, without having to resort to writing and maintaining a GDExtension for all platforms.
- Enable full binary translation to increase performance drastically. Also works on all platforms, but has to be embedded in the project or loaded as a DLL.
- Yields 2.5-10x performance boost by default, 5-50x with binary translation
- Experimental JIT builds are also available in the Releases section for Windows and Linux. The JIT will enhance performance automatically in the background for all programs.
- Publish and then make updates without re-publishing
- You can distribute programs from a server to clients as part of the login sequence. You can use this to live-distribute changes like bugfixes or even new features to the game without having to re-publish the game itself. I do this in my game.
-
Write C++ or Rust in the Godot editor. An accompanying ELF resource is created. This resource can be loaded into any Sandbox instance on every platform without recompiling.
-
Create a new
Sandbox
and assign the ELF resource to it- Lifetime as any other node
- Auto-completion from other GDScripts using @export
-
Or, directly assign an ELF script resource to a node
- Shared sandbox among all instances with that script
- Maximum scalability
- Call functions and attach signals like GDScript
#include "api.hpp"
static int coins = 0;
static Variant reset_game() {
coins = 0;
return Nil;
}
static inline void add_coin(const Node& player) {
coins ++;
// In our demo project we can access the coin label from the player
// using a node path: Player -> get_parent() -> Texts -> CoinLabel
Label coinlabel = player.get_node<Label>("../Texts/CoinLabel");
coinlabel.set_text("You have collected "
+ std::to_string(coins) + ((coins == 1) ? " coinyboys" : " coins"));
}
static Variant _on_body_entered(CharacterBody2D body) {
if (body.get_name() != "Player")
return Nil;
get_node().queue_free(); // Remove the current coin!
add_coin(body);
return Nil;
}
static Variant _ready() {
if (is_editor_hint()) {
get_node().set_process_input(false);
}
return Nil; //
}
static Variant _process(double delta) {
if (is_editor_hint()) {
AnimatedSprite2D sprite("AnimatedSprite2D");
sprite.play("idle");
sprite.set_speed_scale(1.0f);
}
return Nil;
}
static Variant _input(InputEvent event) {
if (event.is_action_pressed("jump")) {
get_node<Node2D>().set_modulate(0xFF6060FF);
} else if (event.is_action_released("jump")) {
get_node<Node2D>().set_modulate(0xFFFFFFFF);
}
return Nil;
}
int main() {
ADD_API_FUNCTION(_on_body_entered, "void", "CharacterBody2D");
ADD_API_FUNCTION(_ready, "void");
ADD_API_FUNCTION(_process, "void", "double");
ADD_API_FUNCTION(_input, "void", "InputEvent");
ADD_API_FUNCTION(reset_game, "void");
}
Script of a simple Coin pickup, with a counter that updates a label in the outer tree. This script can be attached to the Coin in the editor just like GDScript.
You may also have a look at our demo repository for the Godot Sandbox. It's a tiny platformer that uses C++ and Rust. There is also a 3D plane demo that enables controlling the plane from C++ scripts.
In order to build module, add it to a godot repo:
git submodule add https://github.com/libriscv/godot-sandbox modules/sandbox
cd modules/sandbox
git submodule update --init --recursive
Requirements:
If you want to contribute to this repo, here are steps on how to build locally:
./build.sh
You can also use scons
similar to how godot-cpp addons are built.
Thanks goes to these wonderful people (emoji key):
Alf-André Walla 💻 |
K. S. Ernest (iFire) Lee 💻 🔬 |
Dragos Daian 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
The Jenova Framework has a built-in C++ compiler, and supports writing C++ in the Godot editor with hot-reloading support.