Can't properly use custom reward

Hello everyone,

I’m trying to use AI planner custom reward for the first time, and it doesn’t work as expected for me.

The use case is simple, I have a Client (trait) with these fields:

6137826--669618--upload_2020-7-27_18-16-3.png

To simplify, a Client has only 2 actions, it can:

  • Plays (during X ticks)
  • Stops to play

My goal here is to increase the chance for the Client to stop to play according to the time he already played.

Reading the documentation, the proper way to do that is using a custom reward for the StopToPlay that checks the PlayTicks property of the Client. (but maybe I’m on the wrong track, please tell me if there is another way)

So here is my custom reward struct:

public struct StopToPlayReward : ICustomActionReward<StateData>
{
    public float RewardModifier(StateData originalState, ActionKey action, StateData newState)
    {
        TraitBasedObjectId clientId = newState.GetTraitBasedObjectId(action[0]);
        TraitBasedObject client = newState.GetTraitBasedObject(clientId);
        Client clientTrait = newState.GetTraitOnObject<Client>(client);

        if (clientTrait.PlayTicks == 0)
            return -1;

        return clientTrait.PlayTicks / 100f;
    }
}

And here is the action to stop to play:

FYI, the action to play has a reward of 5.

But in game, the value to go to the “Stop to Play” action never change.

Did I do something wrong? Is that how it should be used? When are these reward modifiers called?

Thank you in advance for your help!

When you added the custom reward, did you regenerate your action code?