All Questions

Community

D
Clifford Dutka
posted to: The Idle state

owner vs _state_machine

I'm curious, in the physics_process, you use the owner variable to test if the character is on the floor; however then, when you want to transition states you use _state_machine. Is there a reason for this? It seems more consistent to keep using the owner for transition states as well.

  • Nathan Lovato replied

    The owner, that is to say the Player here, is the node that the states take control of or manipulate. The Player isn't a StateMachine and shouldn't be: it's due to that single responsibility principle.

    The Player node itself represents the playable character in the game world, that's its main responsibility. It's the thing you move and that can collide with walls and the floor.

    The StateMachine is a programmer's tool that just manages states: it ensures that, among a tree of possible behaviors, only one is running at a time.

    It's possible to have both in the Player node, but as your game gets more complex, it would make maintenance harder. With the setup we use, working in a team, if anyone is looking for the state machine, it's clearly there as a node and a self contained branch of your scene.


  • D
    Clifford Dutka replied

    Thank you for your quick reply, after sleeping on it, I realized that I had confused myself on the owner and came to post that I realized the Player was the owner not the State Machine. I'm not sure why I thought the State Machine was the owner.