SwitchState cannot access StateMachine.SwitchState(State)

Hello

I am just trying to follow along and I can’t overcome the error CS0122 inside the PlayerStateMachine.sc.
I have rewatched the videos and looked at the code and just need a helping hand.

SwitchState in the PlayerStateMachine seems to not be able to switch state because the script doesn’t inherit from PlayerBaseState…? But it’s the same as what Nathan instructed?

Plz send help! sos!

Your SwitchState in the base class is private (no access modifier = private). You should make it public or at the very least protected. (Nathan’s is public)

image
This should be

public void SwitchState(State newState)
// or
protected void SwitchState(State newState)

Other classes can’t access private members. protected members are ‘private’, too, but can be accessed by inheriting classes

2 Likes

For future code pastes, please paste in the text of the script rather than screenshots.

In this case, though, it actually was helpful, as your editor was trying to tell you what the issue was:


That’s the editor saying that StateMachine.SwitchState isn’t public.

It needs to be public or the States won’t reach it when they try to SwitchState.

2 Likes

Riiiight, I forgot they get set from within the states.

1 Like

Privacy & Terms