#.WasPerformedThisFrame is called twice.

1 messages · Page 1 of 1 (latest)

icy creek
#

I noticed that the second Called debug has a different callstack than the first.

#

here's the second

faint carbon
#

how is this object created

icy creek
#

this is the function that I'm calling in the game world

        public void Invoke()
        {
            violette.Value = true;
            shion.Value = true;
            textADV.Value = true;
            refInkleStory.Value = inkleStory;

            gameInputBuffer.DisablePlayer();
        }

I thought it had something to do with disabling the inputMap of the player, but isolating it doesn't call the WasPerformed.

icy creek
faint carbon
#

yes

icy creek
#

It's already created "once" in the project. All I need is just reference it anywhere I need input for

faint carbon
#

they work nicely in a build but in the editor it's kind of a crapshoot

#

maybe it's running OnEnable twice over time and therefore you've subscribed twice?

icy creek
#

Assuming that would be the case,
if I press any button, the log should call twice right?

#

I tested that out, was Performed is called once.
it seems to be on a specific situation.

#

lemme make a recording

#

from there reading the log,
I think the problem is this??

        public void Invoke()
        {
            violette.Value = true;
            shion.Value = true;
            textADV.Value = true;
            refInkleStory.Value = inkleStory;

            gameInputBuffer.DisablePlayer(); //<---- I think this is the problem?
        }
#
    public class TestDisable : MonoBehaviour
    {
        [SerializeField]
        private GameInputBuffer gameInputBuffer;

        private void OnEnable()
        {
            gameInputBuffer.OnInteracted += GameInputBuffer_OnInteracted;
        }

        private void OnDisable()
        {
            gameInputBuffer.OnInteracted -= GameInputBuffer_OnInteracted;
        }
        private void GameInputBuffer_OnInteracted()
        {
            gameInputBuffer.DisablePlayer();
        }
    }

and I think I replicated the problem.

#

this test script calls the WasPerformed twice
if I Invoke the action and the invoked action is disabling an input map

tender wind
icy creek
#

@tender wind
I wanted to change the behaviour of the controls in a button press during some parts of my game.

#

Disable one map and enable another

tender wind
#

So, in your case the solution was to move .DisablePlayer() in a separate invocation? I'm trying to make an Input Manager from a Scriptable Object as well, but aside from few forum questions I haven't seen much on this approach.

icy creek
#

I don't have a solution yet to my problem.

#

my only workaround is to add another bool so even if the Interface function get's called again during Disabling, I can at least stop it from evaluating the WasPerformedThisFrame().

#

basically this.

public class GameInputBuffer : ScriptableObject, GameInput.IPlayerActions
{
    public GameInput gameInput;
    public event Action OnInteracted = delegate { };
    public bool isPlayerEnabled;
 
    private void OnEnable()
    {
        if (gameInput == null)
        {
            gameInput = new GameInput();
            gameInput.Player.SetCallbacks(this);
            gameInput.Player.Enable();
            isPlayerEnabled = true;
        }
    }
 
    public void OnButton(InputAction.CallbackContext context)
    {
        if (!isPlayerEnabled) return;
 
        if (context.action.WasPerformedThisFrame())
        {
 
            Debug.Log("Called");
            OnInteracted.Invoke();
        }
    }
 
    public void DisablePlayer()
    {
        gameInput.Player.Disable();
        isPlayerEnabled = false;
    }
}
#

I'm still going to report this as a possible bug

tender wind
#

Wait, is there a difference between using context.action.WasPerformedThisFrame() and context.phase == InputActionPhase.Performed? It never occurred to me that WasPerformedThisFrame can be used inside a callback.

icy creek
#

iirc, context.phase.performed will be called multiple times when you held down the button

#

WasPerfromedThisFrame() is like GetKeyDown() from the classic input