If anyone is trying to follow this and getting stuck at defining the event Action you have to add using.system in order to access Action. The top of the code is cut off in the screenshot so if you're new to C# like me or just forgot that could slip you up.
Ayyy new vid to check out! Oh also, don't know if you remember I was talking about a weird issue with button on hold in the 2021.2 beta. Not sure about exactly what was going on, but looks like as of now value is what's needed to get on hold function to work right at least for clicking with a mouse.
@@OneWheelStudio I hadn't used value in the version released for 2021.1, so I went and checked it real quick and also took a quick check back on your other video, and it seems like value has been reworked to be a bit more like button, and button seems broken in the way value performed if set in 2021.1 how I have it set in 2021.2b. I'm using visual scripting mostly so this might be helping get a bit more info as well, although I'm not very knowledgeable about how stuff is working behind the scenes so might be talking out of my ass here lol. You said that value calls started, performed, and canceled when a value changes. If I set value and have the input system event set for on hold, it'll send two pulses down the flow graph. So perhaps before it was giving one pulse for start, second pulse since it changed value, and after that stalling until release. Not sure if it also sends a third pulse on release due to having states setup to switch on release so I'll need to test that more. In 2021.2b I believe having the action type set to button, and using the on hold event did about the same as that, however it's been a few days since I've really paid attention to see if it was down to sending two pulses as well. Value on the other hand now continues on hold until release. Without digging deeper it's hard to say if they just swapped value and button function or not. Maybe they're planning to remove button and leave it as value and passthrough, while giving value the ability to function as button did. I'll do some more testing tomorrow to see if I can really narrow it down more then take it to the forums, that'll give me an excuse to avoid working on UI haha
Cool. I too was thinking of making some kinda centralised input controller. I foresee too much of a problem with say when you go into or out of a pause menu and the menu controller toggling the appropriate action maps on and off, which in turns also disables the controls for all the other controllers. It maybe be a bit coupled but should be fine for 90% of situations.
Great tutorial. Although I really wanted to know how to handle local multiplayer with vehicles.. still trying to figure it out. Thanks so much for the great content
@@OneWheelStudio ah yeah but the vehicle action map swapping is the real issue. Regardless I'll take a look at your video it might give me a new idea, thanks :)
@@Betruet Hmm. Yeah okay. Makes sense. Happy to help brainstorm solve this one if you want to come on by the OWS discord. Sounds like an interesting challenge.
Thank you, you convinced me to use an InputManager. Is there a way to subscribe input action events in the InputManager rather than the individual script controllers, though?
No I don't like the classes all being able to change the input with static instance. You can either do two things, have the input manager subscribe to and react to external state (this is what I am doing) or you can just inject an instance of the input manager only to classes who need it (like player), this way you won't have that static instance proliferating your code and being changed in places you mistakenly didn't account for.
I was getting errors when trying to create a new InputAction from a Monobehavior. I had to set my inputActions on the InputManager in an Awake function for it to work properly. Awake() { inputActions = new "YourInputActionsNameHere"(); }
Yeah. I've since had similar issues. I've had some odd "race conditions" when using the new system. I'm working on a key rebinding video and ran into them all over the place there. Truly not sure why.
@@OneWheelStudio I had the same, for the time I changed my InputManager script in Script Execution Order to be -50 so it loads before my other scripts, but may be worth looking into Lazy Initialization for it down the road.
Hello, I am using the unity template for a Third Person Shooter game and I don't quite know how to address a certain problem with switching action maps. The sprinting behavior is defined as a Pass Through Action Type and using Invoke Unity Events it simply negates the value of "_sprint" parameter in the player controller. Now the problem is that I have defined another Action Map for the UI and if I hold Shift to run while opening the inventory (and switching to UIActionMap) the value of "_sprint" remains true. Closing the inventory and switching back to the default Action Map results in the inversion of the Shift key behavior (Sprint by default, hold to walk) So my question is: Is there any way to tell the engine to assume KeyUp event on shift key (or every key in general) when switching Action Maps or is there a "cleaner" way to address the behavior of keys that need to be hold for a certain action?
If I subscribe to actions that are part of an action map that is disabled, they don't do anything when the input is used until their action map is swapped in, correct? I'm still struggling to wrap my head around swapping action maps and exactly how everything works. Even using the built in swapactionmaps functionality in the PlayerInput component seemed like it didn't even work half the time or had weird side effects I didn't know how to address because I didn't know what was causing them, so I finally just decided to jump into the fire and attempt learning the ins and outs of the system by bashing my head against the wall long enough.
Yes. If you subscribe to an action that is on a disabled action map nothing should happen. The idea behind changing action maps is to simply enable or disable action maps. The goal of the method presented here is to do that in a controlled or central to keep things tidy.
@@OneWheelStudio I figured out my problem. I forgot to swap my objects to use the static manager so couple of them were still using their own instance and it was causing problems since they thought actions were null since their action maps hadn’t been instantiated. It’s working like a charm now. Thank you for your videos. Several of them have been lifesavers lately, especially as I have been trying to learn the new input system as I’ve refactored over.
I am on Unity 2020.3.18f1 LTS and had a time of my life trying to get the Ui-Input Action Map to work alongside the player Action map. It never does! Do you know how to do that? I found that when I run the game, the player grabs the Player action map and the UI Action map simply does not work. If there is no player at the start of the game it works, so what I did was to start the game without the player accessing the Player Action map and then after the game launched enable the player from the Game Manager in code. This way the UI buttons work alongside the player controls. Has anybody else faced this problem? Do you, One Wheel Studio, know a better way. Thanks for all your tutorials.
I haven't looked into local multiplayer, but my guess would be that you would need to instances of the action map each connected to the different inputs. Unity does have an example that you can download, but I haven't had time to jump into that yet.
I tried to attach the InputManager to a gameobject, but an error is reported in the console. UnityException: CreateScriptableObjectInstanceFromType is not allowed to be called from a MonoBehaviour constructor
It's been a long while since I made this video, but I don't think the InputManager has anything to do with scriptable objects.... Am I wrong? Does the error point to another class that might be listening to an event?
@@OneWheelStudiothe generated csharp wrapper class will try to create a InputActionAsset instance which is a ScriptableObject, its not allowed to create SO in ctor, it must be created in lifecycles like Awake or Start, bc SO has lifecycles too.
I just messed up. I wrote a state machine interface using one of your tutorials and got that working... then i added this input system and when i did that i updated the system making the old input api unusable and now my state machine doesnt work. Im unsure how to make the state machine work with the new input system. since none of my state machine scripts are attached to the player i cant make the action map invoke anything from them.
If you hear into the project setting you can change a setting to use both the old and new input system. Not a perfect solution but might get you moving again.
@@OneWheelStudio thank you, i got it working again. yeah i might wanna just wait to use this new input system for my next game. with my current one i think id have to change alot of work ive already done which would be the second time i did that haha.
@@OneWheelStudio indeed thank you. and thank you so much for your lectures and tutorials about design patterns you have truly helped take my coding to the next level. Now im reworking my state machine into a modular form that i can plug stateActions into by implimenting the strategy pattern. Ultimately id like all my functionality to be modular and workable from the front end as monobehaviors. Trying to sell them on the asset store for some side income. You have been a major contributor so sincerely, thank you again.
If I end up succeeding with this which i believe I will, I would love to contribute to your channel. pretty much my state machine will make calls to the action I place in its Action parameter. So a JumpState will have a JumpAction that stores the functionality. That way you can easily swap it out for another type of jump. Same with the StatManager, The RaycastManager, and other manager i have made. I know im dragging on but honeslty i've never felt more excited to code than now that i have a better understanding of classes and monoBehaviours and these patterns. Two years of study and im finally excited to code lmao
Changing Action Maps Blog Post: onewheelstudio.com/blog/2021/6/27/changing-action-maps-with-unitys-new-input-system
If anyone is trying to follow this and getting stuck at defining the event Action you have to add using.system in order to access Action. The top of the code is cut off in the screenshot so if you're new to C# like me or just forgot that could slip you up.
Thanks! I'm sure you aren't the only one.
I don't know what it is, but your videos are so clear and easy to understand
I'm glad to hear the videos are clear and helpful. 15+ years of classroom teaching are worth something ;)
Ayyy new vid to check out!
Oh also, don't know if you remember I was talking about a weird issue with button on hold in the 2021.2 beta. Not sure about exactly what was going on, but looks like as of now value is what's needed to get on hold function to work right at least for clicking with a mouse.
Good to know. I wonder if it's a bug or a change in functionality?
@@OneWheelStudio I hadn't used value in the version released for 2021.1, so I went and checked it real quick and also took a quick check back on your other video, and it seems like value has been reworked to be a bit more like button, and button seems broken in the way value performed if set in 2021.1 how I have it set in 2021.2b.
I'm using visual scripting mostly so this might be helping get a bit more info as well, although I'm not very knowledgeable about how stuff is working behind the scenes so might be talking out of my ass here lol. You said that value calls started, performed, and canceled when a value changes. If I set value and have the input system event set for on hold, it'll send two pulses down the flow graph. So perhaps before it was giving one pulse for start, second pulse since it changed value, and after that stalling until release. Not sure if it also sends a third pulse on release due to having states setup to switch on release so I'll need to test that more.
In 2021.2b I believe having the action type set to button, and using the on hold event did about the same as that, however it's been a few days since I've really paid attention to see if it was down to sending two pulses as well. Value on the other hand now continues on hold until release.
Without digging deeper it's hard to say if they just swapped value and button function or not. Maybe they're planning to remove button and leave it as value and passthrough, while giving value the ability to function as button did. I'll do some more testing tomorrow to see if I can really narrow it down more then take it to the forums, that'll give me an excuse to avoid working on UI haha
Cool. I too was thinking of making some kinda centralised input controller.
I foresee too much of a problem with say when you go into or out of a pause menu and the menu controller toggling the appropriate action maps on and off, which in turns also disables the controls for all the other controllers. It maybe be a bit coupled but should be fine for 90% of situations.
Great tutorial. Although I really wanted to know how to handle local multiplayer with vehicles.. still trying to figure it out. Thanks so much for the great content
I've got a video on local spilt screen using the new input system. Maybe it'll help? czcams.com/video/l9HrraxtdGY/video.html
@@OneWheelStudio ah yeah but the vehicle action map swapping is the real issue. Regardless I'll take a look at your video it might give me a new idea, thanks :)
@@Betruet Hmm. Yeah okay. Makes sense. Happy to help brainstorm solve this one if you want to come on by the OWS discord. Sounds like an interesting challenge.
Nice! I use a different system but looks like this works too
Thank you, you convinced me to use an InputManager.
Is there a way to subscribe input action events in the InputManager rather than the individual script controllers, though?
No I don't like the classes all being able to change the input with static instance. You can either do two things, have the input manager subscribe to and react to external state (this is what I am doing) or you can just inject an instance of the input manager only to classes who need it (like player), this way you won't have that static instance proliferating your code and being changed in places you mistakenly didn't account for.
hi , there is issue like when i toggleActionMap my player input still works! why this happens ? thanks
I was getting errors when trying to create a new InputAction from a Monobehavior. I had to set my inputActions on the InputManager in an Awake function for it to work properly.
Awake()
{
inputActions = new "YourInputActionsNameHere"();
}
Yeah. I've since had similar issues. I've had some odd "race conditions" when using the new system. I'm working on a key rebinding video and ran into them all over the place there. Truly not sure why.
@@OneWheelStudio I had the same, for the time I changed my InputManager script in Script Execution Order to be -50 so it loads before my other scripts, but may be worth looking into Lazy Initialization for it down the road.
Yeah. That's essentially what I did. Lots of checks for null... Not pretty. Not the way I like to do things, but it does work.
Amazing.
action doesn't even look like a real word anymore
The script for the video was hard to read in places! Action, action, action, action...
Hello, I am using the unity template for a Third Person Shooter game and I don't quite know how to address a certain problem with switching action maps.
The sprinting behavior is defined as a Pass Through Action Type and using Invoke Unity Events it simply negates the value of "_sprint" parameter in the player controller.
Now the problem is that I have defined another Action Map for the UI and if I hold Shift to run while opening the inventory (and switching to UIActionMap) the value of "_sprint" remains true.
Closing the inventory and switching back to the default Action Map results in the inversion of the Shift key behavior (Sprint by default, hold to walk)
So my question is: Is there any way to tell the engine to assume KeyUp event on shift key (or every key in general) when switching Action Maps or is there a "cleaner" way to address the behavior of keys that need to be hold for a certain action?
Under "interactions" you can set hold, tap and press (plus a couple others) to better define the behavior. Hope that helps.
If I subscribe to actions that are part of an action map that is disabled, they don't do anything when the input is used until their action map is swapped in, correct? I'm still struggling to wrap my head around swapping action maps and exactly how everything works. Even using the built in swapactionmaps functionality in the PlayerInput component seemed like it didn't even work half the time or had weird side effects I didn't know how to address because I didn't know what was causing them, so I finally just decided to jump into the fire and attempt learning the ins and outs of the system by bashing my head against the wall long enough.
Yes. If you subscribe to an action that is on a disabled action map nothing should happen. The idea behind changing action maps is to simply enable or disable action maps. The goal of the method presented here is to do that in a controlled or central to keep things tidy.
@@OneWheelStudio I figured out my problem. I forgot to swap my objects to use the static manager so couple of them were still using their own instance and it was causing problems since they thought actions were null since their action maps hadn’t been instantiated. It’s working like a charm now.
Thank you for your videos. Several of them have been lifesavers lately, especially as I have been trying to learn the new input system as I’ve refactored over.
I am on Unity 2020.3.18f1 LTS and had a time of my life trying to get the Ui-Input Action Map to work alongside the player Action map. It never does! Do you know how to do that? I found that when I run the game, the player grabs the Player action map and the UI Action map simply does not work. If there is no player at the start of the game it works, so what I did was to start the game without the player accessing the Player Action map and then after the game launched enable the player from the Game Manager in code. This way the UI buttons work alongside the player controls. Has anybody else faced this problem? Do you, One Wheel Studio, know a better way. Thanks for all your tutorials.
Hmm. Not sure what the issue is - hard to say without seeing the code. Sounds like the action maps aren't getting enabled/disabled correctly.
Model color darkens when exporting to FBX file
If this system was to be used in a splitscreen game, would you need to have an ActionMap for each player in a list and only adjust the relevant one?
I haven't looked into local multiplayer, but my guess would be that you would need to instances of the action map each connected to the different inputs. Unity does have an example that you can download, but I haven't had time to jump into that yet.
Invoke unity events?
I tried to attach the InputManager to a gameobject, but an error is reported in the console. UnityException: CreateScriptableObjectInstanceFromType is not allowed to be called from a MonoBehaviour constructor
It's been a long while since I made this video, but I don't think the InputManager has anything to do with scriptable objects.... Am I wrong? Does the error point to another class that might be listening to an event?
@@OneWheelStudiothe generated csharp wrapper class will try to create a InputActionAsset instance which is a ScriptableObject, its not allowed to create SO in ctor, it must be created in lifecycles like Awake or Start, bc SO has lifecycles too.
oh no... that's a no go solution too... because onEnable s are not strictly executed after all Awake s across objects...
I just messed up. I wrote a state machine interface using one of your tutorials and got that working... then i added this input system and when i did that i updated the system making the old input api unusable and now my state machine doesnt work. Im unsure how to make the state machine work with the new input system. since none of my state machine scripts are attached to the player i cant make the action map invoke anything from them.
If you hear into the project setting you can change a setting to use both the old and new input system. Not a perfect solution but might get you moving again.
@@OneWheelStudio thank you, i got it working again. yeah i might wanna just wait to use this new input system for my next game. with my current one i think id have to change alot of work ive already done which would be the second time i did that haha.
A mid project switch would be difficult for sure! Glad it’s working again.
@@OneWheelStudio indeed thank you. and thank you so much for your lectures and tutorials about design patterns you have truly helped take my coding to the next level.
Now im reworking my state machine into a modular form that i can plug stateActions into by implimenting the strategy pattern.
Ultimately id like all my functionality to be modular and workable from the front end as monobehaviors. Trying to sell them on the asset store for some side income.
You have been a major contributor so sincerely, thank you again.
If I end up succeeding with this which i believe I will, I would love to contribute to your channel.
pretty much my state machine will make calls to the action I place in its Action parameter. So a JumpState will have a JumpAction that stores the functionality.
That way you can easily swap it out for another type of jump.
Same with the StatManager, The RaycastManager, and other manager i have made.
I know im dragging on but honeslty i've never felt more excited to code than now that i have a better understanding of classes and monoBehaviours and these patterns. Two years of study and im finally excited to code lmao
unclear
MAYBE CYRPTO BRO