How to adjust hold time via script ?

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

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.

Alright, so i will wait until then, set it to a global value and do it later. Thank you for the fast reply!

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() 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 )

var isFiring = m_controls.Player.Shoot.ReadValue<float>() >= InputSystem.settings.defaultButtonPressPoint;

Adding a simple wrapper for this is on the list.

Sadly it stays on false, if i click on that button or not.

 m_controls.Player.Shoot.performed += ctx => StartShooting();
private void Update()
    {
        var isFiring = m_controls.Player.Shoot.ReadValue<float>() >= InputSystem.settings.defaultButtonPressPoint;

        Debug.Log("isFiring: " + isFiring);

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() 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() 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() should indeed return default(float).

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!

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 ?

No, that sounds like a bug.

I have opened a ticket for it. → 1195498

1 Like