After following the steps below, you should have a project structure similar to the HelloWorld sample.
(The HelloWorld sample has some extra UI elements in the XAML file that aren't included in the steps below, as they aren't relevant to setup Estragonia.)
- Download Godot Engine version 4.3.0 or later, with .NET support.
- Create a new Godot project or open an existing one. It must use either the Forward+ or Mobile renderer.
- Add a new Godot
Control
node to your scene. In this example, name itUserInterface
. - In the inspector for the newly created control, under Focus, ensure that
Mode
is set toAll
. If you don't, Godot won't pass keyboard input to it. - Attach a new C# script to the previously created control. It should be automatically named
UserInterface.cs
.
📖 Refer to the official Godot documentation if needed.
- Open the .NET solution created by Godot in your favorite editor.
- Install the JLeb.Estragonia NuGet package inside your project.
- Install an Avalonia NuGet theme package: we're going to use the official fluent theme. Without a theme, Avalonia won't display anything.
- Change the previously created
UserInterface
class to inherit fromJLeb.Estragonia.AvaloniaControl
instead ofGodot.Control
. - Either remove the auto-generated
_Ready
and_Process
overrides or ensure the base method is called (otherwise the Avalonia control won't be rendered). - As with a normal Avalonia project, Estragonia needs an
Avalonia.Application
-derived class.
Create theApp
type in XAML (or C#), and ensure it has aFluentTheme
style. - Initialize Avalonia using
AppBuilder.Configure<App>().UseGodot().SetupWithoutStarting()
.
While this can be called inside theUserInterface._Ready
method, it will only work for a single control as the application must be initialized only once. If you plan to have severalAvaloniaControl
instances, we recommend to use a Godot autoload script or a C# singleton, which is what is done in the sample in theAvaloniaLoader
class. - Create a new Avalonia view: it's recommended to inherit from
UserControl
. In this example, name itHelloWorldView.axaml
. - Populate your view with Avalonia controls as you would do in a standard Avalonia application.
In this example, we're using a simple<TextBlock Text="Welcome to Avalonia in Godot!" />
- Assign the view to the
UserInterface.Control
property in the_Ready
method:Control = new HelloWorldView()
.
Don't forget to call thebase._Ready()
after.
📖 Refer to the official Avalonia documentation if needed.
Several Avalonia designers exist, see this Avalonia documentation page.
To get your Godot .NET project to be compatible with these designers, it needs a few things:
- Add a new class with a
void Main()
and aAppBuilder BuildAvaloniaApp()
methods.Main()
won't be called by the designer: it's only used to find theBuildAvaloniaApp()
method next to it. - In
BuildAvaloniaApp()
, returnAppBuilder.Configure<App>().UseSkia()
. Do NOT callUseGodot
as the designer doesn't run inside Godot and doesn't have access to its functions. See Designer.cs for the final file. - Set an executable output type for the project, by adding the
<OutputType>Exe</OutputType>
property to the .csproj file. This is needed to getMain()
to be recognized as an entry point. - Ensure your XAML files don't use any Godot class directly.
- While the scripts created by Godot don't use any namespace by default, we recommend using one anyway as it's pretty standard in .NET: it helps organizing types.
- Since Avalonia has nullable annotations, consider enabling nullable reference types using
<Nullable>enable</Nullable>
in your csproj file to get nullable warnings.