twodog.Engine
Configures, starts, and owns one embedded Godot instance.
public class Engine : IDisposablePackage: 2dog.engine
Namespace: twodog
Constructor
public Engine(string project, string? path = null, params string[] args)| Parameter | Description |
|---|---|
project | Project name passed as Godot's first argument |
path | Directory containing project.godot; adds --path when set |
args | Additional Godot command-line arguments, passed unchanged |
Use ResolveProjectDir() for path in a standard 2dog host. The value comes from the host project's <GodotProjectDir> setting.
Properties
Tree
public SceneTree Tree { get; }Returns the active scene tree. Access it only after Start() succeeds.
NativePath
public string? NativePath { get; init; }Loads an exact desktop libgodot file instead of selecting a packaged variant. Leave this unset in normal hosts. It is not supported in the browser.
ProjectAssemblyDir
public string? ProjectAssemblyDir { get; init; }Sets the preferred directory for the game's C# assembly. The default is AppContext.BaseDirectory; custom isolated hosts may need a different path.
LoadedNativePath
public static string? LoadedNativePath { get; }Returns the full path of the loaded desktop libgodot, when known.
Methods
Start
public GodotInstance Start()Starts Godot and the project's run/main_scene, then returns its running instance. Starting a second classic instance before disposing the first throws InvalidOperationException.
Run
public void Run(Action? perFrame = null)Runs the main loop after Start().
- On desktop, it blocks until Godot requests exit.
perFrameruns after each completed frame that did not request exit. - In the browser, it registers the Emscripten main loop and returns immediately.
Dispose
public void Dispose()Stops and destroys the instance owned by this engine. Dispose the GodotInstance first.
ResolveProjectDir
public static string ResolveProjectDir()Returns the absolute GodotProjectDir embedded in loaded assembly metadata. It throws InvalidOperationException when no loaded assembly provides that metadata.
RegisterWebPluginsInitializer
public static void RegisterWebPluginsInitializer(IntPtr initializer)Registers the game assembly's generated plugin initializer in a browser host. The web host's Program.cs calls this before Start() with the pointer from TwoDogWebBoot.PluginsInitializer() (the bootstrap file in the web host folder, compiled into the game assembly); normal application code does not need anything beyond that template line. Desktop calls throw PlatformNotSupportedException.
Example
using Godot;
using Engine = twodog.Engine;
internal static class Program
{
[STAThread]
private static void Main(string[] args)
{
using var engine = new Engine("MyGame", Engine.ResolveProjectDir(), args);
using var godot = engine.Start();
while (!godot.Iteration())
{
// One frame has completed.
}
}
}Common Godot Arguments
| Argument | Purpose |
|---|---|
--headless | Run without a window |
--verbose | Enable verbose logging |
--debug | Enable debug mode |
--rendering-driver <driver> | Select a rendering driver, such as opengl3 |
--audio-driver <driver> | Select an audio driver, such as Dummy |
See Generic Host for the full desktop-host pattern.