Module cost

Cloud Code has a free tier so that you can start developing and launch with it for free. You only start paying once your organization scales beyond the free tier or any applicable credit allowance.

You can find more details and the pricing FAQ on the UGS product pricing overview page.

Using Cloud Code with Unity services

When you use Cloud Code with Unity services, you are billed for the usage of the services you use. For example, if you call the Cloud Save service from Cloud Code, you are billed for both the Cloud Save call and the Cloud Code invocation.

For more information, refer to the Unity services pricing page.

Using Push messages

When you use the Cloud Code WebSocket feature to push messages to clients, it's important to consider your network usage and the associated costs.

Egress costs

Each message you send from your module to a client consumes network bandwidth, which contributes to the total amount of outbound data from your module. Cloud Code adds the network usage associated with pushing messages over the WebSocket connection to your Cloud Code egress costs.

It's important to consider the egress costs when you design your application and decide when and how often to send messages. Excessive or unnecessarily large messages can lead to higher egress costs.

To learn more about Cloud Code pricing, refer to the Cost page.

Message size limit

Cloud Code limits messages that you send over the WebSocket connection to 10 KB in size. This means you need to manage the size of the data that you send, especially for more complex or data-heavy applications.

You can use the methods below to make sure you keep your players informed and up to date, and also keep your costs and network usage low:

MitigationUse whenAchieved by
Send a diff of the data.You need to communicate a large amount of data or a significant change in game state.Send a diff of the data rather than the entire payload. A diff is a set of changes that you apply to the existing state, which is often much smaller than the full state data.
Prompt a HTTP request for the data.The full data set is large and only needs infrequent updates, or it's more efficient or cost-effective to retrieve data via HTTP.Use the WebSocket message as a nudge mechanism to inform the client that new data is available and prompt it to make an HTTP request to retrieve the full data set.

Cloud Code cost

Costs are calculated over three categories:

CategoryDescription
InvocationsInvocations count the successful Cloud Code module function execution requests within your organization. A successful execution covers any request that returns any response from the module with an HTTP 200 status code.
Compute hoursCompute hours is the time spent executing Cloud Code module functions within your organization. Executions can also include additional warm-up time.
EgressEgress measures the size of responses (in GB) from successful Cloud Code module function executions within your organization. A successful execution covers any request that returns a response from the module with an HTTP 200 status code.

Cost saving tips

To reduce your cost using Cloud Code, follow the tips below:

  • Ensure module function responses only contain data that you use. Unused data contained in module function responses still contribute to your egress costs.
  • Ensure your Cloud Code module functions complete within the allotted 15 second timeout. An accidental while(true) loop can generate unexpected costs.
  • Consider whether you can batch executions together. For example, the Cloud Code module function FuncExampleB might depend on the response from FuncExampleA. If you call these individually, it can cost double the amount compared to if you combine the logic of both into one module function request.

Command batching

Command batching is a concept where each game action is a command that you can collect into a queue and send to the server in batches to process. For more information, refer to the Command batching page.

For example, consider a game that distributes rewards after every action by calling Cloud Save to distribute player XP and Economy to distribute coins. The player completes the following three actions:

  • The first action results in 100 XP and 10 coins.
  • The second action results in 50 XP and 5 coins.
  • The third action results in 200 XP and 30 coins.

These three actions result in a minimum of six calls to various Unity services (in this case, Cloud Save and Economy) if you execute them independently. However, you can store all three of these actions as batch commands and process them through a single Cloud Code module function request. This means that your game only has to make two Unity services calls: one to Cloud Save to increase XP by 350, and one to Economy to add 45 coins.