Search Unity

Question regarding polled actions

Discussion in 'Input System' started by Jichaels, Mar 18, 2020.

  1. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Just a small question that I couldn't find an answer on the doc :

    When using polling, I use an InputActionReference, then on Update I do :

    reference.action.ReadValue<T>


    but I see that the getter for .action is doing a lot, including a new. Is it safe to cache the action in a field in Awake, then use this field to ReadValue for the entire application lifetime ? Or is there something that I'm not aware of that could change this ?

    Ping @Rene-Damm :D
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    The lookup happens only once and is cached internally (well, except if it fails -- might be we should protect against that). So manually caching shouldn't be necessary, though doing so is safe.

    Just noticed that we no longer need the "new Guid" part in there. The code will now look up by ID string just fine. Will remove that part.
     
  3. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    Ok cool, thanks for the quick answer ! Will keep using .action then if there is no overhead