# \[Deprecated] Account Balances

{% hint style="danger" %}
Due for Removal, please speak to support for further info.

**09/06/2025:** MSquared will no longer be supporting "currency" as a concept. If you want similar functionality, it will need to be implemented via an alternative service, e.g. the [KV Store](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/online-services/kv-store-service).
{% endhint %}

## Overview

The inventory system supports items being assigned a quantity. By reading and writing the quantity number you can implement various in-game balances and currencies, and things like:

* Metagame numbers such as XP, Ranks, High Scores
* Consumables, such as potions
* Achievement progress amounts

## Integration

The currency system currently supports two types of currencies, online and offline. Online currencies persist in a player's Collection, and in turn persist across deployments and events. Offline currencies doesn't interact with the user's collection and so don't persist, but can be used for transient currencies or point systems.

### Creating a currency

To create a currency, create a new Data Asset of type `J_CurrencyTypePrimaryAsset`. Once that has been created, open it up and fill in the details. If you want this to be an "online" currency then tick the `IsCollectionCurrency` check box. You will also need to fill in `DataSourceId` and `ObjectId` - refer to the Online Mode section to see where to get those details. If you are making an offline currency then leave these two blank, and `IsCollectionCurrency` unselected.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-22f37e872879600dfb8b7ec43d59f1a2ebc9e068%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Online Mode**

Online currencies require an object definition to be created in the back end. If your project supports it, you may be able to create a user collection object yourself using the web UI - simply add a new object into a non-public collection with some kind of asset (usually a thumbnail image), and ensure it has a currency property by entering `{ "currency" : "" }` in the Properties section.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-59f739e2cb842de910cb9bf34a27e7a444e639eb%2Fimage.png?alt=media" alt=""><figcaption><p>Adding a new Currency object</p></figcaption></figure>

The `DataSourceId` and `ObjectId` for your object can be seen in the Datasource view as shown:

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-388611640b8aa2707c9c72a1eefba29e7ffeaf53%2Fimage.png?alt=media" alt=""><figcaption><p>Datasource and Object IDs</p></figcaption></figure>

Alternatively, contact a member of the platform team and a Support Engineer can create the object for you. Once they have created the object definition, they will be able to inform you of the `DataSourceId` and `ObjectId` to use.

Using an online currency also requires that user collections are enabled on the server. Ensure that the following `game` live config value is enabled: `UserCollection.EnabledOnServers`

### Offline Mode

For an offline currency this isn't required - simply fill in the standard details in the data asset and you can start using it.

## How to enable

Your player Morpheus blueprint should already inherit from `BPM_M2_BasePlayerCharacter`. In this case it will already have a wallet component attached.

To make sure the balance is updated, you will need to turn on User Collection Polling using the [Live Config](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/live-config) setting `UserCollection.Polling.ClientEnabled` - see [here](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/live-config/overriding-default-live-config-settings) how to overrride this.

To interact with the players wallet you use the `J_CurrencySubsystem`. This has functions to get, give and take currency from the player's wallet. Examples of each of those can be seen below. Getting a currency can be done on a client, but giving or taking must be done from the server.

{% hint style="warning" %}
**Note**: Currently due to limitation of the collection system, getting a currency can only be done on the client if it is an online currency. You may receive a message saying "`User collection service is invalid`" when you run the editor in offline mode.
{% endhint %}

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-3b087b6932daa99c4052f61fbcbf9e4b3687ac26%2Fimage.png?alt=media" alt=""><figcaption><p>Example of getting a currency</p></figcaption></figure>

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-d79009b89baa2c016254435886e601157d965cc5%2Fimage.png?alt=media" alt=""><figcaption><p>Example of giving currency</p></figcaption></figure>

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-e1885bb7d1b7afaeb4686446097901642af81e82%2Fimage.png?alt=media" alt=""><figcaption><p>Example of taking currency</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.msquared.io/creation/unreal-development/features-and-tutorials/accounts/account-balances.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
