Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Switching Object Possession Mid-Input

Discussion in 'Input System' started by GuitarBro, Aug 30, 2020.

  1. GuitarBro

    GuitarBro

    Joined:
    Oct 9, 2014
    Posts:
    180
    I have a game where the player can run up to a vehicle and begin controlling it on contact (and later go back to walking on foot). Currently I am using an in-house player controller system inspired by UE4's game framework to dictate which object is currently being controlled. My initial thought was to simply bind/unbind the input actions to the player/vehicle when possession changes, but naturally performed events only happen for one of the objects (whichever was bound at the time) and thus the input must be re-triggered in order for the newly possessed object to become aware of it occurring.

    Another possibility seems to be the "polling method" where every input is queried in Update() but this seems like it could become expensive very fast with enough vehicles, and generally seems to not be a very elegant solution.

    Binding inputs to every object the player can potentially control and simply ignoring the ones not needed isn't an option for me for similar reasons.

    What is the paradigm I should follow for sending input events between the player and the player's vehicle such that input events (such as holding forward) aren't missed when the possession changes?