Toggle an Interaction
Use this graph for a door, switch, platform, or other interaction that has stable states and must finish its transition before accepting the opposite command.
In the editor
- Add standalone Idle states named Closed and Open, plus Action States named Opening and Closing. Arrange them in that loop.
- The two Idle states keep the stable modes Running. Do not add Idle to an Action State’s Action list.
- Connect Closed to Opening and Open to Closing. Replace the default State Finished on both transitions with Has Received Event, use Continuous evaluation and Receive Mode: Latest, and assign the same targeted Event Name, such as
Interact. - Configure Opening to play the opening animation and sound. Use Parallel Execution Type when both should start together and the state should finish only after both complete.
- Configure Closing with the corresponding closing Actions.
- Connect Opening to Open and Closing to Closed with State Finished.
The supplied State Designer samples use the reusable DoorInteract Subgraph for this kind of animation-and-audio interaction. Keep the state machine on a controller GameObject when an Action may disable the visible object.
How it runs
Closed waits for the Interact event, then enters Opening. While Opening is active, another event does not take the Open-to-Closing transition because Open is not active yet. After every Opening Action finishes, State Finished enters Open. The next Interact event begins Closing, which completes before returning to Closed.
Separating the stable and in-progress modes prevents overlapping open and close sequences. The active state also gives other systems a clear answer about whether the interaction is closed, moving, or open.
Key choices
- Keep Receive Mode: Latest for discrete interaction presses that should not queue during Opening or Closing. Queued retains events across activations and can trigger another transition when the next stable state starts. Use a boolean Condition when an external system owns a persistent desired state.
- Choose Sequence when animation, sound, and gameplay changes must happen in order. Choose Parallel when they should begin together.
- Add an Any-to-Locked or Any-to-Disabled transition when one condition must interrupt both stable states, but decide explicitly whether it may interrupt Opening and Closing.
- Export the interaction as a Subgraph when several doors share the flow, then override animation clips, sounds, and target objects per reference.
Verify in Play Mode
Send Interact while Closed and confirm the active highlight advances through Opening to Open. Send it again and confirm Open advances through Closing to Closed. Repeated input during an in-progress state should not start the opposite transition early.