#.actions problem in c#

1 messages · Page 1 of 1 (latest)

cobalt solar
#

The Problem: > I am trying to use .actions in the image but instead VS cannot identify ".actions".

What I’ve Tried:

Looking everywhere in the inspector for if anything related to the Player Input component (the input action asset)

I've tried removing it, but another error appears, saying that i must refer to a gameobject, even though im not.

Relevant Code/Setup:

Engine: Unity 6000.3.10f1 (windows)

Script:
1 using UnityEngine;
2 using UnityEngine.InputSystem;
3
4 public class PlayerBehaviour : MonoBehaviour
5 {
6 PlayerInput playerInput;
7 InputAction moveAction;
8
9 [SerializeField] float playerSpeed;
10
11 // Start is called once before the first execution of Update after the MonoBehaviour is created
12 void Start()
13 {
14 playerInput = GetComponent<PlayerInput>();
15 moveAction = playerInput.actions.FindAction("Walking");
16 }
17
18 // Update is called once per frame
19 void Update()
20 {
21 MovePlayer();
22 }
23
24 void MovePlayer()
25 {
26 Debug.Log(moveAction.ReadValue<Vector2>());
27 //Vector2 direction = moveAction.ReadValue<Vector2>();
28 //transform.position += new Vector3(direction.x, 0, direction.y) * Time.deltaTime * playerSpeed;
29 }
30 }

Console Errors:
i)Assets\Scripts\PlayerBehaviour.cs(15,34): error CS1061: 'PlayerInput' does not contain a definition for 'actions' and no accessible extension method 'actions' accepting a first argument of type 'PlayerInput' could be found (are you missing a using directive or an assembly reference?)

ii [if i remove .actions])NullReferenceException: Object reference not set to an instance of an object
PlayerBehaviour.MovePlayer () (at Assets/Scripts/PlayerBehaviour.cs:26)
PlayerBehaviour.Update () (at Assets/Scripts/PlayerBehaviour.cs:21)

#

Help would be much appreciated...
...please?

quasi pagoda
#

again, have you checked that PlayerInput is using the one from input system? you can check by hovering over PlayerInput

cobalt solar
#

this is all i know

#

it looks like it is

quasi pagoda
#

that doesn't seem right

#

that's saying it's from an asset

#

did you import an inputsystem asset or something? i think that would be very outdated as it's published as a package now

cobalt solar
#

idk wdym but

#

ik that this is unity 6000.3.10f1

quasi pagoda
#

try ctrl+click on that PlayerInput. it seems like that would be a class in Assets.

cobalt solar
#

again idk whats going on here

#

but it seems like it isn't a class in assets

quasi pagoda
#

this is in assets

cobalt solar
#

ok

#

what should i do

quasi pagoda
#

you have an inputactionsasset asset named PlayerInput, and you've generated a class for it. so the class is named PlayerInput, and that's clashing with the inputsystem PlayerInput that you're trying to access

#

if you aren't using this you can just disable generating this class and delete the class

cobalt solar
#

should i just delete public InputActionAsset asset ( get; )

quasi pagoda
#

that's not what i said, no.

cobalt solar
#

and wdym disable generating

quasi pagoda
#

there is a checkbox labelled "generate c# class" when you select the inputactionsasset in unity

cobalt solar
#

And when I try to off it it still doesnt work idk

#

Also, another error appeared, but i looked it up on google it said that I have to resolve everything else so ye