Question by
sandi397 · Feb 08, 2021 at 04:34 PM ·
inputpublicpublic variable
Public InputController class not showing on inspector
I have created an Input controller for my game and auto genereted a class for it. Now i try to include that class as a public variable on my PlayerController and subscribe move and jump actions to it, but the problem i have is my public variable doesnt show up. I am using Unity 2020.2.3 version of Unity.
Here is my PlayerController class:
public class PlayerController : MonoBehaviour
{
//PRIVATE
private Rigidbody2D Rb;
private bool CanJump = true;
//PUBLIC:
public float Speed;
public float JumpStrength;
public InputController inputController;
private void OnEnable()
{
inputController.Enable();
}
private void OnDisable()
{
inputController.Disable();
}
private void Awake()
{
inputController.Player.Jump.performed += _ => Jump();
inputController.Player.Move.performed += ctx => Move(ctx.ReadValue<float>());
}
void Start()
{
Rb = GetComponent<Rigidbody2D>();
}
void Update()
{
}
private void Jump()
{
//Debug.Log("jump");
if (CanJump)
{
Rb.velocity = Vector2.up * JumpStrength;
}
}
private void Move(float moveInput)
{
Rb.velocity = new Vector2(moveInput * Speed, Rb.velocity.y);
//Debug.Log(moveInput);
}
}
And here is a picture where i only see the speed and jump height but not InputController:
screenshot-5.png
(12.4 kB)
Comment
What is the InputController
class?
If it's not a class inheriting from UnityEngine.Object, you need to add the [System.Serializable]
attribute to the class definition.
[System.Serializable]
public class InputController
{
...
}
Unfortunately this does not solve my problem.
Here is my input class:
// GENERATED AUTO$$anonymous$$ATICALLY FRO$$anonymous$$ 'Assets/Scripts/InputController.inputactions'
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class @InputController : IInputActionCollection, IDisposable
{
public InputActionAsset asset { get; }
public @InputController()
{
asset = InputActionAsset.FromJson("some json text i dint copy because it was too much characters....");
// Player
m_Player = asset.FindAction$$anonymous$$ap("Player", throwIfNotFound: true);
m_Player_Jump = m_Player.FindAction("Jump", throwIfNotFound: true);
m_Player_$$anonymous$$ove = m_Player.FindAction("$$anonymous$$ove", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? binding$$anonymous$$ask
{
get => asset.binding$$anonymous$$ask;
set => asset.binding$$anonymous$$ask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
// Player
private readonly InputAction$$anonymous$$ap m_Player;
private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Jump;
private readonly InputAction m_Player_$$anonymous$$ove;
public struct PlayerActions
{
some player actions i did not copy...
}
public PlayerActions @Player => new PlayerActions(this);
public interface IPlayerActions
{
void OnJump(InputAction.CallbackContext context);
void On$$anonymous$$ove(InputAction.CallbackContext context);
}
}
i was following this tutorial on youtube: NEW INPUT SYSTE$$anonymous$$ in Unity