Search Unity

Discussion Frame-by-frame or Callback

Discussion in 'Input System' started by Wilhelm_LAS, Aug 24, 2023.

  1. Wilhelm_LAS

    Wilhelm_LAS

    Joined:
    Aug 18, 2020
    Posts:
    55
    For instance, i have a "Fire" action which is dependent to "Player" Action Map inside an Input Action Asset.
    As far as from my researches, it is simplified to do with PlayerInput component.
    We define which Input Action Asset and which Action Map as default should be used in PlayerInput component.
    And lastly, we define which Behaviour PlayerInput Component should use to send actions into the desired GameObject. For me, it is set to "Invoke Unity Events" so that way i will bind them from Player Input.

    Now i can create either `OnFire()` and instantiate the ProjectTile and check the UI with custom raycasts or hook that to `Update()` to get input frame by frame and check the raycast with IsPointerOverGameObject().
    The problem is, the OnFire method can be invoked when u press UI too. This is can be avoided by using IsPointerOverGameObject()
    There is a sample for that inside New Input System package. It says:

    Since you cannot use IsPointerOverGameObject() inside Action Callback, you may need to use `RaycastAll()`

    My question is, which one(Update approach - Callback[OnFire]) is performant and why?
    Second question is, either Event.current.RaycastAll or Event.current.IsPointerOverGameObject() is more performant?