# Retrieve Assets In-Game

In this How-to we will demonstrate how to fetch an Asset from the backend to be displayed in your game.

### Prerequisites

* A LootLocker account
* A created game in the web console
* An active Asset

## Retrieve Asset

To start retrieving assets you can run following:

{% tabs %}
{% tab title="Unity" %}

```csharp
int count = 10;
LootLockerSDKManager.GetAssetListWithCount(count, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved " + response.assets.Length + " assets");
    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/9nGchIIjm1uKU11cwj5q" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/yy2u_t10/">Blueprint example of how to retrieve assets</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

After the initial method has completed retrieving assets you can call this method to get more:

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.GetAssetNextList(count, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved second batch of " + response.assets.Length + " assets");
    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
});
```

{% endtab %}
{% endtabs %}

If you want to retrieve all you assets you can keep calling the method until you stop receiving assets.

After finishing retrieving the assets you need, it's best practice to run the following code, as if you try to get assets later, you might start from your previous last retrieved asset.

{% tabs %}
{% tab title="Unity" %}
{% hint style="warning" %}
This is only relevant for Unity! This is not the case for Unreal.
{% endhint %}

```csharp
LootLockerSDKManager.ResetAssetCalls();
```

{% endtab %}
{% endtabs %}

## Retrieve Assets With Filter

{% tabs %}
{% tab title="Unity" %}

```csharp
int count = 10;
List<LootLocker.LootLockerEnums.AssetFilter> filter = new List<LootLocker.LootLockerEnums.AssetFilter>() { LootLocker.LootLockerEnums.AssetFilter.nonpurchasable };

LootLockerSDKManager.GetAssetListWithCount(count, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved " + response.assets.Length + " assets");

    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
}, filter);
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/50P5d2UdkapRXFVs3YUa" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/yy2u_t10/">Blueprint example of how to retrieve assets</a></p></figcaption></figure>

To use Filters, simply specify the filter you want to retrieve assets with, through the same blueprint as before.
{% endtab %}
{% endtabs %}

## Retrieve Assets by IDs

If you already know the IDs of the assets you wish to get, you can use this method to retrieve them specifically.

{% tabs %}
{% tab title="Unity" %}

```csharp
string[] list = new string[] { "8111" };

LootLockerSDKManager.GetAssetsById(list, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved " + response.assets.Length + " assets");
        Debug.Log("First Asset ID: " + response.assets[0].id);

    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/2m5lOLnU4UudXzJSJnrE" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/-gad8mpe/">Blueprint example of retrieving assets by ids</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Retrieve Favourite Assets

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.ListFavouriteAssets((response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved " + response.favourites.Length + " assets");

        if (response.favourites.Length > 0)
        {
            Debug.Log("First Asset ID: " + response.favourites[0]);
        } else
        {
            Debug.Log("No favourite assets");
        }
    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/bxB64DCsWfzwACezfUfN" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/l_nly9_z/">Blueprint example of retrieving favourite assets</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Add Favorite Asset

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.AddFavouriteAsset("8111", (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully favourited asset");
    }
    else
    {
        Debug.Log("Error favouriting asset");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/Jjxy3WyoKd3kuyHx3n3j" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/_ks_jxkb/">Blueprint example of adding an asset to Favourites</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Remove Favourite Asset

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.RemoveFavouriteAsset("8111", (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully removed favourite asset");
    }
    else
    {
        Debug.Log("Error removing favourite asset");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/gDO9AlljIaOiei61dSOp" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/dopxy04m/">Blueprint example of removing an asset from Favourites</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Working With Assets For Player in Game

### Get All Key Value Pairs to an Instance <a href="#getting-all-key-value-pairs-to-an-instance" id="getting-all-key-value-pairs-to-an-instance"></a>

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.GetAllKeyValuePairsToAnInstance(45781352, (response) =>
{
    if (response.success)
    {
        if (response.storage.Length > 0)
        {
            Debug.Log("Successfully retrieved " + response.storage.Length + " key value pairs");
        }
        else
        {
            Debug.Log("No key value pairs for asset instance");
        }
    }
    else
    {
        Debug.Log("Error retrieving assets");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/EflVW05hgUzImIWEHYyM" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/yywi40l6/">Blueprint example of retrieving all key value pairs</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

### Get A Key Value Pair By Id <a href="#getting-a-key-value-pair-by-id" id="getting-a-key-value-pair-by-id"></a>

{% tabs %}
{% tab title="Unity" %}

```csharp
int assetInstanceID = 84;
int keyValueID = 1;
LootLockerSDKManager.GetAKeyValuePairByIdForAssetInstances(assetInstanceID, keyValueID, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully retrieved key value pair");
    }
    else
    {
        Debug.Log("Error retrieving key value pair");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/oWMiEHevS1dHA3cuEmIQ" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/6yxyyy80/">Blueprint example of getting a specific key value pair</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

### Create A Key Value Pair <a href="#creating-a-key-value-pair" id="creating-a-key-value-pair"></a>

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.CreateKeyValuePairForAssetInstances(45781352, "some-new-key", "value here", (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully created key value pair for asset instance");
    }
    else
    {
        Debug.Log("Error creating key value pair");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/50vvxCNl34XDP7Sp8a4Z" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/2ad9sijo/">Blueprint example of creating a key value pair</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

### Update One Or More Key Value Pairs

{% tabs %}
{% tab title="Unity" %}

```csharp
int assetInstanceID = 84;

Dictionary<string, string> multipleTestKeys = new Dictionary<string, string>();

multipleTestKeys.Add("some-new-key", "Some value");
multipleTestKeys.Add("some-other-key", "Some other value");
LootLockerSDKManager.UpdateOneOrMoreKeyValuePairForAssetInstances(assetInstanceID, multipleTestKeys, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully updated key value pairs");
    }
    else
    {
        Debug.Log("Error updating key value pairs");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/gtRGSuEhf1ta2ksxHD5B" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/cpnudhzd/">Blueprint example of updating one or more pairs</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

### Delete Key Value Pair

{% tabs %}
{% tab title="Unity" %}

```csharp
int assetInstanceID = 84;
int keyValuePairID = 1;

LootLockerSDKManager.DeleteKeyValuePairForAssetInstances(assetInstanceID, keyValuePairID, (response) =>
{
    if (response.success)
    {
        Debug.Log("Successfully removed key value pair");
    }
    else
    {
        Debug.Log("Error removing key value pair");
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="/files/fEEaU8Qdcy8PNkctqccc" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/mrdw8dd2/">Blueprint example of deleting a key value pair</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}


---

# 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.lootlocker.com/content/working-with-assets/how-to/retrieve-assets-in-game.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.
