Inputreader script non functional

so I am doing the Unity 3rd Person Combat & Traversal course and I am on section 2 lesson 12 and I came across these errors: [15:40:11] Assets/Scripts/StateMachine/Player/PlayerTestState.cs(13,22): error CS0117: ‘StateMachine’ does not contain a definition for ‘InputReader’

[15:40:11] Assets/Scripts/StateMachine/Player/PlayerTestState.cs(25,22): error CS0117: ‘StateMachine’ does not contain a definition for ‘InputReader’

this is the PlayerTestState Script:

using System.Collections.Generic;
using UnityEngine;

public class PlayerTestState : PlayerBaseState
{
    private float timer;

    public PlayerTestState(PlayerStateMachine stateMachine) : base(stateMachine) { }
 
    public override void Enter()
    {
        StateMachine.InputReader.JumpEvent += OnJump;
    }

    public override void Tick(float deltaTime)
    {
        timer += deltaTime;

        Debug.Log(timer);
    }

    public override void Exit()
    {
        StateMachine.InputReader.JumpEvent -= OnJump;
    }

    private void OnJump()
    {
        stateMachine.SwitchState(new PlayerTestState(stateMachine));
    }
}

this is the StateMachine script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class StateMachine : MonoBehaviour
{

    private State currentState;

   public void SwitchState(State newState){
     currentState?.Exit();
     currentState = newState;
     currentState?.Enter();
   }
   
   private void Update()
    {
        currentState?.Tick(Time.deltaTime);
    }
}

and this is the InputReader Script

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class InputReader : MonoBehaviour, Controls.IPlayerActions
{

    private Controls controls;
    private event Action JumpEvent;
    private event Action DodgeEvent;

    private void Start(){
        controls = new Controls();
        controls.Player.SetCallbacks(this);
        controls.Player.Enable();
    }

    private void OnDestroy() {
        controls.Player.Disable();
    }

    public void OnJump(InputAction.CallbackContext context){
        if (!context.performed) { return; }
        JumpEvent?.Invoke();
        
    }

     public void OnDodge(InputAction.CallbackContext context){
        if (!context.performed) { return; }
        DodgeEvent?.Invoke();
     } 

}

Hi @Ethan_Elzer. Welcome to the community. Check in the inspector for the Player State Machine. Do you have the Input Reader linked up?

I would not be able to tell because the inspector shows me this under both of my script components: The associated script can not be loaded. Please fix any compile errors and assign a valid script.

Therefore it would have to be in the code

In InputReader.cs, the private event Action lines need to be public. This is the only thing in InputReader.cs that is different than in my project. I don’t see anything different with your StateMachine.cs. Unfortunately, I did not keep the PlayerTestState.cs so I can not check that one.

that still did not do it. i will check the repo for any differences

I was not sure if that was the problem. I will wait to see if someone more experienced that me can help. You should add the tag from the video so that the TA will be notified. Each video has a code in the lower right hand corner under the video player. I think the one you are on is 7_SM_UTP.

StateMachine here should not be with an uppercase S. It should be stateMachine. I am, of course, assuming you followed the course convention

This is very likely the issue.

that was it. thank you!’

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms