#.WasPerformedThisFrame is called twice.
1 messages · Page 1 of 1 (latest)
Putting this here so others can post normally.
Basically I just registered in a scripableobject and use that SO whenever I need it.
https://pastebin.com/GkF6Q8MY
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I noticed that the second Called debug has a different callstack than the first.
here's the second
how is this object created
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.
the SO?
yes
It's already created "once" in the project. All I need is just reference it anywhere I need input for
So the weird thing about ScriptableObjects is that lifecycle functions like ONEnable are very strange in the editor
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?
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
Why do you disable an input map during Invoke()?
@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
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.
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
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.