Connect WebGL with a backend?

Sorry that this question may be silly or previously answered but I’m super new to Unity and I almost confused myself by searching for the answer for several days by googling.

I have a game built on WebGL but then I need to connect the game with a script written in Python (essentially the backend?) to compute in real-time and change parameters in scripts written in C# that will control GameObjects.

I was thinking to use Cloud Service such as Google Cloud PubSub for this but then I realize I can probably just put them on the same server. However, I’m also quite new to server setup… The only thing I learned is that I could set up a LAMP stack to deploy the game in WebGL format, but I’m not sure how C# scripts can “communicate” with python scripts after they are packed into WebGL format. Is this even possible?

Here’s the manual page for communicating to/from webGL (with javascript)
https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

1 Like

So is using Javascript the only possible way to communicate to/from webGL?

1 Like

You may want to look at something like Azure Functions, which are basically a function that exists on a server as an API endpoint, that your game can call.

Azure Functions supports Python, so you can create your Azure Function using Python, and then have your Unity game call the function using a Unity WebRequest.

Here are the docs on creating an Azure function in Python.

1 Like