The Wayback Machine - https://web.archive.org/web/20231104091819/https://github.com/UnityTechnologies/open-project-1/pull/114
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced StateTransitionSO with TransitionTableSO + Editor #114

Conversation

DeivSky
Copy link
Contributor

@DeivSky DeivSky commented Oct 27, 2020

Generic State Machine

I've replaced StateTransitionSO workflow with a TransitionTableSO workflow. In the TransitionTableSO we list all the possible transitions of a StateMachine and feed that into the SM instead of the initial StateSO. The initial state is now the first "FromState" in the transition table.

Having the transitions decoupled from the states allows for different setups without having to duplicate states just because one transition is different. And having the transitions in a single SO allows for easy reusability.

The decoupling is only present in the editor. At runtime, the states still hold their own transitions and have them fed from the transition table during initialization. We could decouple the runtime as well by having the SM handle the transitions, but it wouldn't really change anything. Rather, it'd add an extra bit of overhead because it'd rely on lookups.

I've set up the transition table for the main character and it seems to be working just as before. Do test, though, and let me know if you spot anything.

Credit to @kcastagnini since the idea comes from his FSM implementation.

I've added a complete editor for the transition table for easier usage.
image

image

Patch notes:
Created TransitionTableEditor and StateEditor.

  • TransitionTableEditor allows you to fully configure the transition table in an easy way.
  • A list of the states in the table is displayed, with the initial state at the top.
  • States can be sorted manually to change the initial state or just for ordering.
  • The order of the states bellow the initial shouldn't affect the behaviour of the state machine.
  • Added buttons to easily switch back and forth between state editor and transition table editor.
  • The state editor is a simple reorderable list with all the action in the state.
  • Clicking on a state will display all of its transitions, along with their conditions.
  • Transitions can be sorted to change the order in which checks are executed.
  • Transitions can be removed.
  • Conditions can be easily added, removed and sorted through reorderable lists.
  • New transitions can be added with the + button underneath the states list.
Created TransitionTableEditor and StateEditor.
- TransitionTableEditor allows you to fully configure the transition table in an easy way.
- A list of the states in the table is displayed, with the initial state at the top.
- States can be sorted manually to change the initial state or just for ordering.
- The order of the states bellow the initial shouldn't affect the behaviour of the state machine.
- Added buttons to easily switch back and forth between state editor and transition table editor.
- The state editor is a simple reorderable list with all the action in the state.
- Clicking on a state will display all of its transitions, along with their conditions.
- Transitions can be sorted to change the order in which checks are executed.
- Transitions can be removed.
- Conditions can be easily added, removed and sorted through reorderable lists.
- New transitions can be added with the + button underneath the states list.
@DeivSky DeivSky changed the title Replaced StateTransitionSO with TransitionTableSO Replaced StateTransitionSO with TransitionTableSO + Editor Oct 29, 2020
@kcastagnini
Copy link

This looks neat man. This weekend I will dive in into the code!

@DeivSky
Copy link
Contributor Author

DeivSky commented Oct 29, 2020

This looks neat man. This weekend I will dive in into the code!

Thanks! Editor code might be a little messy because I was learning on the fly, I'm gonna try to clean it up, but do check it out and tell me your thoughts!

@ciro-unity ciro-unity added the enhancement New feature or request label Oct 29, 2020
@ciro-unity ciro-unity changed the base branch from main to state-machine-improvements November 8, 2020 16:33
…-tables

# Conflicts:
#	UOP1_Project/Assets/ScriptableObjects/Protagonist/Transitions/BeginJumpDescent.asset
#	UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateTransitionSO.cs
@ciro-unity
Copy link
Contributor

I merged it into a new branch state-machine-improvements, but there's a few UX issues that I think should be solved before we move forward with this solution:

  • In dark UI mode, the Transition Table Inspector is very hard to read:
    image

  • It's quite annoying that when inspecting actions, I can't see their values and I cannot select the asset to change them. You can switch the SO for a new one, but you can't inspect the one currently selected...
    image

@ciro-unity ciro-unity merged commit a5a9018 into UnityTechnologies:state-machine-improvements Nov 8, 2020
@DeivSky DeivSky deleted the fsm-transition-tables branch November 8, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
3 participants