Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Can't properly use custom reward

Discussion in 'AI & Navigation Previews' started by Noxalus, Jul 27, 2020.

  1. Noxalus

    Noxalus

    Joined:
    Jan 9, 2018
    Posts:
    76
    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:

    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:

    Code (CSharp):
    1. public struct StopToPlayReward : ICustomActionReward<StateData>
    2. {
    3.     public float RewardModifier(StateData originalState, ActionKey action, StateData newState)
    4.     {
    5.         TraitBasedObjectId clientId = newState.GetTraitBasedObjectId(action[0]);
    6.         TraitBasedObject client = newState.GetTraitBasedObject(clientId);
    7.         Client clientTrait = newState.GetTraitOnObject<Client>(client);
    8.  
    9.         if (clientTrait.PlayTicks == 0)
    10.             return -1;
    11.  
    12.         return clientTrait.PlayTicks / 100f;
    13.     }
    14. }
    And here is the action to stop to play:

    upload_2020-7-27_18-22-36.png

    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.

    upload_2020-7-27_18-26-16.png

    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!
     
  2. TrevorUnity

    TrevorUnity

    Unity Technologies

    Joined:
    Jun 28, 2017
    Posts:
    101
    When you added the custom reward, did you regenerate your action code?
     
unityunity