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".
Here's how I solved it in FastAPI: