Energy system in Unity

:tv: Media:

Hi guys,

I want to ask something related to energy systems: Energy - Heroic Labs Documentation

I’ve created a energy system that refills with certain parameters. That works well. But I am wondering why is it not visible or exposed a function to grant energy to the player. As stated in the documentation there are plenty ways or needs from design to do so: after watching an ad, after finishing certain mission,…, you name them.

I’ve observed is part of the player’s storage so in theory I can create a hookup with my connection handler to modify that value {"count": XXX, from the storage but I am not sure if that will work and if so…feels like a bit hacky wether having a function exposed like the spending one will be fantastic

await energiesSystem.SpendEnergyAsync("lives", 1);

Thanks, Sam.

Hey @SamFashionLeague :wave:

As stated in the documentation there are plenty ways or needs from design to do so: after watching an ad, after finishing certain mission,…, you name them.

The reason we don’t expose a client method to directly grant energy is because its usually handled server-side. What is the source of the reward you want to grant to the player to increase their energy count?

from the storage but I am not sure if that will work and if so…feels like a bit hacky

You’re absolutely right. It’s definitely not recommended to directly modify any of the storage objects used by the gameplay systems to maintain their state. These data objects could be changed over time as the Hiro library improves and you don’t want your own code to break.

function exposed like the spending one will be fantastic

We can add a client function to let you recover energy directly from some action you want to take on the game client but can you share the specific use case you’d like to solve. For example you mentioned rewarded video but usually this is handled with the current features in Hiro called (Ad) Placements:

{
    "...": "...",
    "placements": {
        "recover_energy_ad": {
            "reward": {
                "guaranteed": {
                    "energies": {
                        "some_energy_type": {
                            "min": 5
                        }
                    }
                }
            },
            "additional_properties": {}
        }
    }
}

Thanks for your response @novabyte

Maybe I am not understanding well the system but for example if you watch an ad you usually receive a callback response from the SDK you are using to indicate that the economic reward is being granted so you can now reward your users. This is to me the moment I would reward our players internally with whatever you decide and this is where I expected to call something similar to energiesSystem.GrantEnergyAsync("lives", 1);

There are few uses I would like to trigger this. For example:

  • when finishing a certain level in game for example beating a boss (not linked to any reward or monetisation system)
  • when watching the ad (you mentioned the placements)
  • when cheating for dev (there is a way by just modifying the storage manually but not handy for non-tech people)
  • when daily login award.

I also want to ask if for example, the granted reward given by a placement is instant or player needs to login again. I would assume needs to be instant otherwise we are losing a lot but then how is this done?

Thanks, Sam.

Maybe I am not understanding well the system but for example if you watch an ad you usually receive a callback response from the SDK you are using to indicate that the economic reward is being granted so you can now reward your users.

@SamFashionLeague Most Ad mediation services support server-side callbacks when Ad watches are completed and Hiro provides a fallback mechanism as well for when some Ad networks do not report the callback (i.e. Admob).

when finishing a certain level in game for example beating a boss (not linked to any reward or monetisation system)

I assume this would be an interstitial Ad which shows at the end of the level. You would show the Ad via the mediation SDK and then inside its callback you could call:

await economySystem.PollPlacementStatusAsync("someAdPlacementId");

when cheating for dev (there is a way by just modifying the storage manually but not handy for non-tech people)

You shouldn’t never need to manually update any storage objects which are created by Hiro in the gameplay systems. If you want to just grant energy to the player from some debug UI on the client you can use:

await energySys.GrantAsync(...);

I would assume needs to be instant otherwise we are losing a lot but then how is this done?

Reward grants are always instant, you may need to refresh the gameplay system’s state but if you have an observer registered you’ll get a “signal” for when the response produced a state change:

SystemObserver<EnergiesSystem>.Create(energiesSystem, system =>
{
    // Update game UI.
});

when daily login award.

With a daily reward I’d just define an achievement which can grant it and resets each day:

{
    "achievements": {
        "daily_reward": {
            "name": "Daily Reward",
            "description": "Login for the first time today.",
            "category": "daily",
            "count": 0,
            "max_count": 1,
            "reset_cronexpr": "0 0 * * *",
            "reward": {
                "guaranteed": {
                    "energies": {
                        "lives": {
                            "min": 5
                        }
                    }
                }
            }
        },
        // ...
    }
}
1 Like