#it doesnt transition to an attackState,
1 messages · Page 1 of 1 (latest)
Can you distill this down to an outsider? Where is your code that is suppsoed to transition? What logs have you put around that code? Is it actually running? What logs are printing and when?
generally if "it's not doing XXX" that means the code to do it isn't running
You need to first confirm that with logs and then you work backwards from there to figure out why
The code responsible for state transitions is in StateMachine.cs within the ChangeGunState() method. I've set up logging to track the current state using "GetType().Name". Additionally, there's an error log if no new state is active. In PatrolState.cs, the CanSeePlayer method checks if the enemy detects the player using a ray. Here's the sequence: Enemy_1 Start() method starts, confirms the StateMachine component presence, ChangeGunState method sets PatrolState as the new state, and the Perform() method detects the player and transitions to AttackState. Finally, CanSeePlayer confirms player presence and then later indicates player absence. the print is of what it should be trasitioning to the AttackSState
first one is called once while the rest is update
Looks like it's transitioning just fine - but it seems really weird that you're creating a new AttackState there
Why don't you show these logs though:
Debug.Log("Changing gun state. gunActiveState: " + (gunActiveState != null ? gunActiveState.GetType().Name : "null"));
Debug.Log("New state: " + newState.GetType().Name);```
both are called once
that looks like it's going to patrol state
and the previous state was null
that's not attack state
so you're never calling CHangeGunState
which means the state machine reference was null
which brings me back to what I tried to tell you the other day
which is you are failing to set the state machine reference on your states when you are creating them
Remember that whole discussion we had??