- Home /
Does SerializeField work when extending the Input System?
I am extending the new Input System with a custom Processor and Interaction.
Using a public field shows up in the Editor as expected:
public float tweakableValue = 2.5f;
However, I prefer to use SerializeField to indicate that this is set in the Editor and prevent access from other classes:
[SerializeField]
private float tweakableValue = 2.5f;
While this works perfectly well for any MonoBehaviour, it does not show up in the Input Action Editor.
Am I missing something or is this simply not supported by the new Input System? If so, should I report a bug?
Edit: Here is an example where I extend the InputProcessor:
using UnityEngine;
using UnityEngine.InputSystem;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace dyco {
/// <summary>
/// Input processor to rotate a two dimensional input by the configured degrees
/// </summary>
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class RotateProcessor : InputProcessor<Vector2> {
[Tooltip("The angle in degrees to rotate the vector by")]
public float RotateDegrees = 45f;
#if UNITY_EDITOR
static RotateProcessor() {
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Initialize() {
InputSystem.RegisterProcessor<RotateProcessor>();
}
/// <summary>Rotates the given vector <paramref name="value"/> by the configured <see cref="RotateDegrees"/></summary>
public override Vector2 Process(Vector2 value, InputControl control) {
return value.Rotate(RotateDegrees);
}
}
}
Answer by Bunny83 · Jun 23, 2020 at 04:13 AM
How do you extend the input system? Most of Unity's build-in classes have a dedicated custom editor created for that class. So if you derive your own class from one of them, you often have to create / extend the editor as well.
I've edited my answer to include a complete example.
Since the posted version with a public field shows up fine in the Input Action Editor and the SerielizedField shows up fine within the general editor, I don't think I have to extend the Editor as well, but please correct me if that is indeed the issue.
Well in that case you can not use private fields. You do not really instantiate an InputProcessor yourself anywhere. You do not interact with this class anywhere. The input system should do that internally. So where and how would you actually inspect an instance of this class?
As you can read in the documentation, InputProcessors can not have "mutable state" (so no variables which are changed during runtime) but can have "parameters". Those parameters (which have to be public fields) can be set through a json config string or the InputControl attribute like this:
[InputControl(layout = "Axis", processors = "rotate(RotateDegrees=4)"]
public float axis;
Note, as you can read here, since you didn't specify a name for your processor, Unity will automatically take your class name and clips the suffix "Processor" if present. The processor name is not case sensitive.
ps: I haven't use the new input system yet, so I can't say much about it. However as far as I know it's mainly written in plain C#. So most of Unity's reflection serialization magic probably does not apply to those classes. They most likely are not serialized at all. Processors are probably just instantiated once by the system and the system changes the "parameters" as needed. Though that's just a guess ^^.
You can inspect the processor in the editor of an .inputactions asset. It looks like this:
Note: Uploading the file directly gave me an error "Error parsing the uploaded file." and I will remove the link from the cloud storage in the future.
Your answer
Follow this Question
Related Questions
How to consume input when automatically switching control schemes through a Player Input Component 0 Answers
How to mimic Unity's Components based System 1 Answer
Class variable wont show up in inspector with new Unity Input System 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
New Input System 0 Answers