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

How to adjust hold time via script ?

Discussion in 'Input System' started by zh4r0naX, Oct 31, 2019.

  1. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Hi, i want to use the new hold function for a charging laser. While this would work for one laser i want it to dynamically change the hold time based on a float value which is saved in the weapon prefab. How can i modify my Shoot action to recognize the new hold duration ?

    For example iam using this to start the shooting, now i would like to acces the hold time for this action.
    m_controls.Player.Shoot.performed += ctx => StartShooting();

    Can somebody post a snippet for this please ?

    Thank you
    Justin
     
    Last edited: Oct 31, 2019
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    There's currently no support for dynamically changing parameters at runtime. It's on the list for after 1.0.

    ATM it's only possible to change the global defaults dynamically or to write/derive custom interactions that read out their parameters from somewhere else.

    Other than that, it's down to workarounds like setting overrideInteractions on bindings to reconfigure parameters through the string. Or to get ahold of the IInputInteraction object (e.g. from a callback) and cast it to a respective interaction implementation type and then set parameters on that.

    But yeah, a proper mechanism to do all this will be available after 1.0.
     
  3. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Alright, so i will wait until then, set it to a global value and do it later. Thank you for the fast reply!
     
  4. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    While my gun is now charging correctly, i want the gun to fire until the mouse has been released. How can i do a poll with this ? Iam not passing any value when Starting my Shoot function. So how can i detect if the mouse is still pressed after execution of the charging stuff ?

    m_controls.Player.Shoot.ReadValue<bool>() This for example only gives false, maybe because i dont even use a boolean there.
    m_controls.Player.Shoot.triggered gives true only for a second when pressing the action.

    I saw some posts of you, but they dont help me polling this. Because its the same action, basically this gun fires not continously after the charging is finished. So the action is completely done. Gun charges for 2 seconds then fires beam. Action is completed at this stage. Now i want to check if the mouse has been released to cancel the beam. ( Just in case something wasnt clear )
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Code (CSharp):
    1. var isFiring = m_controls.Player.Shoot.ReadValue<float>() >= InputSystem.settings.defaultButtonPressPoint;
    Adding a simple wrapper for this is on the list.
     
  6. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Sadly it stays on false, if i click on that button or not.

    Code (CSharp):
    1.  m_controls.Player.Shoot.performed += ctx => StartShooting();
    Code (CSharp):
    1. private void Update()
    2.     {
    3.         var isFiring = m_controls.Player.Shoot.ReadValue<float>() >= InputSystem.settings.defaultButtonPressPoint;
    4.  
    5.         Debug.Log("isFiring: " + isFiring);
     
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    What's the button bound to? There's a hold interaction on the button, right?

    If the action is enabled and is bound to a button that is pressed and has exceeded the hold time but ReadValue<float>() returns default(float), that would strongly hint at a bug. HoldInteraction is designed to stay in performed phase for as long as the button is held once the hold duration has been reached. This should cause ReadValue<float>() to go to the control and return the current value. If that isn't happening, please file a ticket with the Unity bug reporter.

    The important bit is that the hold time has to be reached. Before that, ReadValue<float>() should indeed return default(float).
     
  8. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    No bug here, but thank you for the reply, found the error. The Shoot action wasnt the hold action. The hold action is named Chargeshot. Both are on one button. Because i need different behaviors for different guns.

    Iam now using the hold action for your code. Now it works. Thank you!
     
  9. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Well it returns true now until the hold duration is exceeded (action.performed state kicks in ). then it stays on false until you click that button again. So it isnt working for my needs right now. Am i doing something wrong ?
     
  10. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    No, that sounds like a bug.
     
  11. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    I have opened a ticket for it. -> 1195498
     
    Rene-Damm likes this.