# 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-841d3aab2f40488d88dd67af43359e2555cc498f%2FGetAssetList.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-fc3d9ec3ad45b8a997947bc77e0bbcc0cb0223c9%2Fimage.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-4498c054f636eace36189b65d473ac3071dfc06d%2Fimage.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-859948c5eda411b97690dd9f83ae8482ebd30c55%2FGetFavouriteAssets.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-1503aeeebb15ab8b66ace032f48c67bd6df1861a%2FAddFavouriteAsset.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-c90dad6ac93d9036ab9a912bf2432e9f21395ad1%2FRemoveFavouriteAsset.png?alt=media&#x26;token=a329ce7e-7479-4800-a9b3-8495a02ef9c1" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-e42d79bdc41ab854854bb215b870a497626009a8%2FGetAllKeyValuePairs.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-07ce9932f4f33ee40b30789713fedfaad067b26a%2FGetSpecificKeyValuePairById.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-7ca657f749bf6c44275460ea743d800530562899%2FCreateKeyValuePair.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-08e4e62312e48fc2e63f6b77951ec0f9a7a3eb89%2FUpdateKeyValuePairs.png?alt=media" 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="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-1a2927a5503180f71cd903189877fc13a6b677c8%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/mrdw8dd2/">Blueprint example of deleting a key value pair</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}
