[.NET] Add web export support#106125
Conversation
Use Mono embedding APIs statically linked to load the Mono WASM runtime.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@raulsntos Will this and other Godot C# full features run smoother in the long run as Godot 5.x? As in developing if Godot 4.x gets prototype C# features (such as web support) running and then in Godot 5.x it is optimized with the 'would be nice' features like size and security optimizations? I say this after reading your and the creative community's comments on the C# suite features and the prototype type work and potential for better solutions ( #70796 (comment) ). DetailsI wonder this in order to better plan big projects (like a working vertical slice C# MIT Smooth Voxel MMORPG template for Godot) be it Godot 4.x and or Godot 5.x due to API and other complex team coordination which requires a stable software platform / game engine to first under take. If a Godot 5.x alpha with C# full features is being built soon (Godot 4.x may already be past its mid-life cycle once 4.5 is stable) it might be better for the 'power users' / big movers / proper game studios of the creative community to 'Wait for Godot' than to force teams of people to re-engine from Godot 4.x to Godot 5.x. Software long term stability is very critical for long term planning.A lot of senior game studios are re-engining now and it is by default UE5 but personally I'd like it to be Godot also. A lot of studios are re-engining from the Unity implosion and I want Godot to succeed where Unity failed. Yet long term stability is very critical for the old grumblers of the industry. Thus starting on a prototype Godot 5.x alpha with full C# features and optimizations and long term stability (and other details that require stability like Godot C# API issues being fully addressed) after ~Godot 4.5 stable is probably a practical way forward for the Godot creative community to keep both near future growth of Godot game engine progressing well and also keep Godot 4.x stable. Godot should get ready for the next gaming generation come 2027 / the late 2020's. Official Godot 5.x alpha plans for a feature roadmap can do a lot to also powerfully grow and future proof the Godot game engine creative community for today's and tomorrow's game building adventures. It seems like Godot 4.x will get unified C# support as a GDextension and full C# parity support; yet this might be as prototype form. Once the Godot 4.x full C# features are operational this whole suite of C# features might require optimizations that are only properly done with seeing everything on the table first in working form and then in a big strong unified effort lead a proper engine rewrite to properly integrate the features to be optimized for being the best they can be. As from what can be currently done as the creative community for this console generation and the next console / gaming generation planned for 2027 / late 2020's with the PS6 / new Xbox / next gen consoles and gaming hardware. The work of https://github.com/raulsntos and friends is very helpful to the creative community and I wish to thank the people involved greatly. This kind of work helps the creative community to make great games for everyone. |
|
When using Firefox with the |
|
Can confirm, with this solution it is possible to make a project with godot4 + .net, and run it on itch.io. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
any updates on this? any chances this pr gets included in 4.5? |
4.5 is in feature freeze, so any new features can only be merged in 4.6 at the earliest. |
Hey @MadBunnyGames - is there any chance you would be willing to share how you got the .net build working? I would be happy to hack together whatever I needed, but it seems like there is minimal action on this recently so would be great if I could get something working for prototyping |
|
I suspect that this PR will be turned down in favor of #110441 ( which superseded #90510 and will turn #106125 unnecessary in the future). As soon as we become able to compile and run godot as a shared library, It will be preferable to compile godot as a wasm sidemodule that will be loaded and initialized by standard .net instead of mono, or am I misunderstanding something? |
|
Worth noting that #110441 does not yet support running C# programs from C# because there's some fiddly changes that need to happen to prevent the two uses of the same environment from stomping on each other, but assuming 110441 is accepted, I'll be putting up a PR for those shortly afterwards; I've been using that on my own framework for months now, so this is at least somewhat battletested. I haven't yet tried to use this to support web export .NET but I don't know of any expected roadblocks. |
|
@Gnumaru @zorbathut would that substantially change how we have to export web builds for dotnet compared to the current process? For current web exports there's simply an export template required to build the web version - will devs now need to compile the godot engine from source to use as a shared library, or will all that be hidden away from users? For example with your framework @zorbathut it requires setting up a whole toolchain for building from source. I'm happy to do it if necessary for the moment, but it's not an ideal experience compared to the current process of just downloading the editor and a template, and then running the web export from inside the editor... |
|
My personal framework requires a compilation framework because I'm a tinkerer and make custom changes to the engine all the time :) I can think of no reason a properly-upstreamed libgodot-based .NET-web-export platform would require that though, it'd be the same user experience as it is today for all the other platforms. A big part of the reason I'm trying to get libgodot upstreamed is so people can take advantage of its features without having to mess around with custom vendoring frameworks like mine. |
|
Very excited to hear about the progress on this! Wishing you all the best of luck in getting this out the door. Once this is in place I can build Godot stuff in C#! |
@zorbathut Ah I understand, yeah it would be great to get it integrated. Getting a web build for C# is the only thing that's giving me a headache at the minute, as otherwise I've found working with Godot such a nice experience to use... |
Basically pulled the changes from here into a 4.4.1 (or some nightly 4.5 dev, not sure), edited the .csproj file to match .net version and threading support, built the editor and the templates (as Godot documentation says... note: I use windows and had to switch to WSL when building the web template, because emscc command was too long for PowerShell), also set up a local nuget store for godot package during build (its in godot docs too), matched my project file, referenced the newly built nugets, needed to add entrypoint to the project (main function), then built and exported the project with the new templates, manually removed the DOTNET.setup(...) call from the .js that was generated for the c# project, then just uploaded to itch as is. |
|
If you want to try out the solution made by @raulsntos and reproduced by @MadBunnyGames and you aware how to use Docker you could try my "one liner" to achieve the web build. Nothing is guaranteed, it's all experimental and may break. P.S. ~4gb will be downloaded by docker to get the image
public class Program
{
public static void Main(string[] args)
{
}
} |
|
Also wanting to know if there's any estimation on release for this, if there's any blockers or help needed please let us know. |
|
Hey there! I'm AR & I have contributed to the .NET backend. We currently can't tell you when this will be merged because as Raul mentioned earlier, there are some issues (The JS one). If you want to compile it yourself, feel free to check out the docs. The PR is also work in progress meaning there will be changes Raul wants to implement before merging, |
|
Ah yeah, the JS issue is a big problem in this preview because Yeah you can think: I don't will use it anyway, but .NET Also I've tried a lot of things trying I also tried to start a concurrent I don't know why .NET can't allow us to "link I also will try compile this preview version with a 4.5 stable version again as I unfortunatelly doesn't have success in the past. I think we just wanna more visibility if we have some news or updates about this theme, because it seems a little abandoned :( |
|
@renanrcp I have asked Raul about it & if he needs any help. Will let y'all know as soon as I get a reply. |
|
Yes, I'm going to work on it. Wooh! Let's just hope it gets implemented :) |
|
I'm so happy to see that @AR-DEV-1, I will help with anything in my range ❤️
The .NET issue is about the dynamic linking for .NET AOT in Web, in this PR we are using mono static linking, the real issue here in my vision is about the I using this preview in a big personal project and it's working very fine. |
|
Ok, trying to discover why this preview doesn't work with 4.5.1 again this week 👀 |
|
From Chat Godot contribution forum
|
Yeah, I'll have a look at that later after I'm free. |
|
Hey @AR-DEV-1 I've tried a lot of things, and I will share with you: About incompatibility with
|
|
Also compiling with template_release we finally got a message error: I also tried to reduce more in .NET ThreadPool 2, 1. But the problem continues, if I increase the emscriptenPoolSize to 16 it fixes, but that's strange, I've checked the flags used for the emsdk and in godot 4.4 it is originally 8 too. |
|
@renanrcp I was switching operating systems (Windows to Linux!). We always appreciate help from the community. I think the error message is a bit weird, can you share the command you used? |
Merge this PR in the 4.5.1-stable branch, change the Then export the Raul's prototype with the template (maybe the .sln file doesn't support the Release as publish mode just insert the lines). You'll see this error in the JS console. If you change the Also, yes I using Linux, Ubuntu 24.04 with latest chrome version. FYI: @AR-DEV-1 |
Curious, how likely godot 4 web export could be embeded in blazor and how the JS interoperability and c# between blazor and embeded godot4 web export could proceed. Interested to learn from you, based on your testing, and added additional files (corebindings.c, JsFunctionBinding (called by source generators), JS Side.), could this be done soon? Did you test your finding with this web demo prototype? |
Hello @GeorgeS2019 I'm too busy in last weeks lol... First of all, yes I've tested everything with Raul's prototype, I'm also have a personal project using it. For this current preview seems impossible to embed blazor in godot4 web export, because blazor really needs I don't have so much knowledge about I will try help with other things but maybe I will be useless outside |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Hi, and thanks for your work on this. I’ve also seen some discussion about using Godot as a library as a possible new approach, and was wondering if that affects the direction here. Any updates would be appreciated, thanks. |
The problem for this feature is If you don't consider |
|
Am i reading right that this is functional as long as you dont need the JSBridge? |
The [JsImport] and [JsExport] of .NET, they use it in some places like HttpClient, WebSocket... You can just use the Godot things and it will work fine. |
|
Sounds useful then. Is there a build for 4.6 somewhere with this commit for testing purposes? The Docker image above doesn't have the source code available, or at least I couldn't find it. Are there plans to add this as it is to the project or are you waiting for a complete solution first? |
Would it make sense to add the current state of the web export to the next Godot version as an experimental feature with clear instructions about what is not supported yet? We have been waiting for a resolution to this problem for 3 years, maybe it makes sense at this point to move this forward in an imperfect way, but at least unblock a majority of game developers trying to make web builds with Godot. |
I've done a public repo for it, but I've built with 4.5.1 in my on machine, it's not hard, just merge this PR with a stable branch like 4.6 and it will work, just setup multithreads in the right way if you wanna use. https://github.com/renanrcp/godot-web-dotnet-building
Yep, you also can use |
|
I've been investigating the JS interop stub replacement problem and have a made some progress with a proof-of-concept that replaces the crypto stub with a real browser implementation. and investigating the JSImport and mainly the whole "How could we hook this all up" Sharing findings here in case they're useful. Also, i know the GodotLib is the way forward, but working on a project now was trying to put together an idea that helps now and get devs building .net to web exports for their projects sooner than later. EnvironmentI am working on this in windows.
My Test CS fileusing Godot;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
public partial class Main : Node
{
public override void _Ready()
{
var bytes = new byte[16];
System.Security.Cryptography.RandomNumberGenerator.Fill(bytes); // I got this working via wasm_entropy stub replacement
GD.Print("Crypto result: " + BitConverter.ToString(bytes));
runHTTP(); // Was tracing the JSImport signatures...
}
private async void runHTTP()
{
try {
using var client = new System.Net.Http.HttpClient();
var response = await client.GetStringAsync("https://httpbin.org/get");
GD.Print("HTTP result: " + response.Substring(0, 50));
}
catch (Exception e)
{
GD.Print("HTTP error: " + e.GetType().Name + ": " + e.Message);
}
}
}
Dealing with initializationAfter exporting and applying the known So I wondered, what it would take to find a way to get to the stubs, so my question was how tied are dotnet.js and dotnet.runtime.js and how much does it need to be setup? Do we HAVE to initialize it or can we find a way to route it ourselves? so I uncommented out the dotnet setup and started with the errors First up, Problem 1:
|
|
Hey @HexBlit can you show the JS file you edited, I wanna check if I can create replacements for |
Use Mono embedding APIs statically linked to load the Mono WASM runtime.
GetRuntimePackC# project. It needs thewasm-toolsworkload.GetRuntimePackdefines stub functions for all the function pointers we need to retrieve from C#, so thePInvokeTableGeneratorincludes them in the generatedpinvoke-table.hfile.dotnet.runtime.jsmodule but we don't have an easy way to do that yet, which means some BCL APIs will not work (i.e.: crypto APIs)Warning
This is still a work in progress, but it should be possible to export a C# game to web with some manual changes to the exported
.jsafterwards.This PR was tested with the demo project: Web .NET prototype
Note
The demo project requires multi-threading, so make sure to change the
<WasmEnableThreads>property totrueto use the right Mono runtime.