Call from Unity game server (Multiplay Hosting)
You can call a script from a dedicated game server using Multiplay Hosting.
Prerequisites
- The game server you are invoking Cloud Code from and any related resources must exist in the same Unity Cloud Dashboard project and environment.
- Onboard with Multiplay Hosting.
Call out to Cloud Code
Follow the steps below to call out to a Cloud Code script from a game server.
Authentication
You can authenticate requests using a Multiplay Hosting token or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header.
Authenticating with a Multiplay token is recommended. Authenticating with a stateless tokens requires you to create a service account and store the private key securely, whereas Multiplay tokens do not require this and are less complex to manage.
Authenticate using a Multiplay Hosting token
See the Game Server Documentation here.
Authenticate using a stateless token
To use a stateless token, you need to create a service account and call the Token Exchange API. Refer to authenticating trusted clients for the Cloud Code Client API.
Call a script
You can call the script using any HTTP library that is native to the codebase. Use the retrieved authentication token as a bearer token for HTTP authentication in the request header. An example CURL request to call a script using the Cloud Code API could look like this:
curl -X POST -H "Authorization: Bearer <BEARER_TOKEN>" 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>'