How to make a skill cooldown system with Rental Assets in Unity

Unity
Assets
Author image
Johannes Fornaeus5 min read
Cover image

Rental assets are a really easy way to create consumable items for your game that are removed after a set amount of time. So that’s things like boosters, buffs, skills, or cooldowns for abilities, as well as consumable items like potions, herbs, or strength enhancers. You can do this either as a timed booster, or a temporary buff or debuff for your game.

Rental assets are great for in-game rewards, time-limited events, claimable items during an in-game event… the list goes on. A rental asset can also contain other assets – so you can make these as simple or complex as you want.

Before we get started

Before we begin, make sure you've created your free LootLocker account, and installed and configured the Unity SDK into your game project.

You’ll also need to have got to grips with a few other LootLocker concepts before you can start using rental assets. Those are:

All sorted? Then let’s begin.

Rental assets in detail

Let’s have a look at rental assets in action. In this example, we’re using the rental asset to activate a consumable booster for the player to use. When that happens a particle effect plays for the same length of time as the rental asset.

Remember that you need to activate rental assets – they can’t be equipped. So if your rental asset contains other assets, you’ll first need to activate the rental asset. Then, if you want the player to equip it directly, equip the items you get in return from the response.

Setting rental assets up using the LootLocker dashboard

  1. Create a rental context
    Go to “Settings” then “Contexts”. Click “Add Context”, give it a name, then choose “Rental Asset” from the dropdown list under “Complexity”. Then tick which character classes can use the rental asset. Don’t forget to save it.

  • Create the new asset
    Next we head to “Content”, then “Assets”. Create a new asset with the rental complexity context we just made.
  • Add assets on the “Rental Content” tab
    We can now see two new tabs – “Rental Content” and “Rental Tiers”. This is where we add specific assets that will appear in the player’s inventory when the rental asset is active – like a special sword that only lasts for one minute, for example. You can leave this blank if you want to use the rental asset for something that only applies to your game during the time the booster’s active.
  • Set up the duration on the “Rental Tiers” tab
    Use this tab to set up how long the rental asset will last. You can have several durations on the same asset. For example, if you have an XP boost in your game, you can use this tab to give it different levels. That means you only need to create one asset with different tiers, rather than several with the same information.
  • Implementing rental assets in Unity

    Get the player’s inventory with the GetInventory()-function. LootLocker will then return information for all the assets in the player’s inventory.

    We can then run a check to see if it’s a rental asset, and if the player’s consumed it, by checking the rental.time_left property on the asset. If the time_left is 0 or below, that means the rental asset isn’t active anymore, and shouldn’t be shown in the inventory. If the time_left isn’t up, we can show it in the player’s inventory with the function HandleItem().

    In this example we’re running the UseItem()-function when the player clicks the asset in their inventory, which checks if they can equip the item. If they can, we run LootLockerSDKManager.EquipIdAssetToDefaultCharacter() to do that.

    Next we check if it’s a rental asset. If it’s a yes, we activate it by running LootLockerSDKManager.ActivatingARentalAsset(), and send in the asset instance ID we got from the previous response.

    We’ve now activated the rental asset on the server. That means it’ll be removed from the player’s inventory after a specific length of time. So we need to start a timer with the same duration as the rental asset, and display a particle effect during this time. When the time’s up, the particle effect ends.

    One thing to remember – when players quit or pause the game in the middle of an active rental, the timer on the server doesn’t stop. So you’ll need to ask the server for the remaining time left on the rental asset again to keep it in sync.

    And that’s it – rental assets, done.

    Need some help?

    Hopefully, you’re now super comfortable with rental assets. Don’t forget about LootLocker’s other features though – they’re all really quick and easy to set up. And if you need some help, we have lots of guides available.

    Any questions?

    Get in touch on Twitter or Discord. And if you like these guides, please let me know by tweeting me directly – I’d love to hear from you.

    Stay up to date.

    Join our newsletter and get these posts sent directly to your inbox.