Exiting Targeting state after attacking

I have now noticed that when entering attacking state the function Exit() in Targeting gets called, so the target gets wiped and player always enters free look mode. After checking github all of my code is exactly the same. Any idea what could be wrong here considering that in the videos it’s staying in the proper state?

Hi, welcome to the community. Can you post the exit method from your PlayerTargetingState?

Sure, it is
public override void Exit()
{
stateMachine.Targeter.Cancel();
stateMachine.InputReader.CancelEvent -= OnCancel;
}

exactly like in the course

the targeter cancel method is

public void Cancel()
{
if (CurrentTarget == null) {return;}
cineTargetGroup.RemoveMember(CurrentTarget.transform);
CurrentTarget = null;
}

all of my script is exactly like in the course, so I’m very confused why its working different

The line that reads:

stateMachine.Targeter.Cancel();

should not be there. Comment it out and test. The only thing Exit should be doing is unsubscribing to the event.

1 Like

Oh, I never noticed that it is supposed to be in OnCancel instead of Exit. I’ve been comparing it hundreds of times and it kept blending together. Thanks

1 Like

Glad I could help. Sometimes looking at the same lines over and over can be hypnotic.

1 Like

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

Privacy & Terms