Hi all.
I’m having some trouble with switching weapons in what I’m currently developing (a weapon system). What’s a good way to handle input using the new input system for weapon switching?
I have a WeaponManager-script that creates the weapons under an empty gameobject as weapon-parent. And each weapon has a PlayerInput-script and a Weapon-script attached to it. I’m using Invoke Unity Events behavior on the PlayerInput so I can hook up different scripts on it to be triggered.
But when I start a game with multiple weapons created my inputs are sometimes double or even more. Even if the weapons are set to disabled after creation. After switching weapons the inputs are are often triggered even more times. Even when I have code that checks if input was performed.
Weapon.cs has this:
public PlayerInput PlayerInput;
private void OnEnable () {
PlayerInput.ActivateInput();
}
private void OnDisable () {
PlayerInput.PassivateInput();
}
Which per the documentation should enable/disable the inputs on the gameobject.
Here’s a gif with only one weapon created (one casing):
and in this case I added another weapon to be created when I start the game (two casings, second gameobject is disabled):