For Godot 4 and the threads export in Godot 3, you need to set special headers on your web server in order to enable SharedArrayBuffer. There are some examples here for various web servers.
The script below can be used to start a web server that sets the required headers. The easiest way to use this is to place this python script in your export folder and double click it to start the server. Then you can view your game at http://localhost:8000.
If you're curious about the Python web server that Godot itself uses for its "Run In Browser" feature, you can find that here:
https://github.com/godotengine/godot/blob/master/platform/web/serve.py
You can set headers in Apache in an .htaccess
file placed in your project directory, assuming you have AllowOverride
enabled. You can also place this configuration in your Apache config files. This could be placed in a <VirtualHost>
directive or a <Directory>
directive, or probably others. You will need to have mod_headers enabled.
Header set Cross-Origin-Opener-Policy "same-origin"
Header set Cross-Origin-Embedder-Policy "require-corp"
You can add headers in your nginx config file, which will look something like this:
server {
# ... other stuff here ...
location / {
# ... other stuff here ...
add_header 'Cross-Origin-Opener-Policy' 'same-origin';
add_header 'Cross-Origin-Embedder-Policy' 'require-corp';
}
}
When editing your project, under "Embed options", check the box labeled "SharedArrayBuffer support".
When editing your project, check the box labeled "Uses SharedArrayBuffer/Cross Origin Isolation".
The game in the browser was supposed to be a client, connecting to a "normal" server. The idea behind it was that, during development, i could send a link to a friend and be like "playtest this with me for a minute".
I've experimented some more and researched some more but could not get it to work - iirc i also saw someone mention that HTML5 export in Godot 4 does not support websockets properly yet, so after a while i chalked it up to that and decided to try again later.
The documentation on websockets is also still outdated, so once that's up to date i might give it another shot. I'm actually still not sure if i need to allow websockets somehow in my nginx conf or if it really just isn't working properly in godot 4 web exports yet.
The mention about proxing is just because literally EVERY result on google in my search was about proxying things, but in my case i'm running it directly on the nginx server so these results didn't help me. or at least that's how i understand it.