Comments (2)
Hi @TdXYZ,
the current version of UnityHFSM does not directly provide this feature out of the box. You can, however, do this fairly easily yourself:
Instead of creating just one state machine, as you normally would, you create two state machines. Then in the Update
function, you call the OnLogic
method of both state machines. This will run both state machines independently, in parallel.
class Player : MonoBehaviour
{
StateMachine movementFsm;
StateMachine animationFsm;
void Start()
{
movementFsm = new StateMachine();
movementFsm.AddState("Idle");
movementFsm.AddState("Jump");
movementFsm.AddState("Run");
// ...
animationFsm = new StateMachine();
// ...
movementFsm.Init();
animationFsm.Init();
}
void Update()
{
movementFsm.OnLogic();
animationFsm.OnLogic();
}
}
This same pattern can also be repeated to run as many state machines in parallel as you desire.
The implementation for running multiple nested state machines in parallel within a main state machine follows the same idea. The main difference is that their OnEnter
, OnLogic
, and OnExit
functions would be called within an additional state that you have to add to the main state machine.
As this feature seems quite useful, I've created a new state type that does just that for you. It's called ParallelStates
and will be added in the next release of UnityHFSM (2.1). If you want to already use it in the meantime, you can access it in the release
branch.
from unityhfsm.
Thank you very much for adding this. UnityHFSM is one of the best implementations of statecharts out there. Working with the package has given me more ideas on how it can be even better such as history states and tasks, but I'll make separate issues for those.
from unityhfsm.
Related Issues (20)
- Feature request: onEnter and onExit on non-root StateMachines HOT 2
- feature request: OnActiveStateChanged event? HOT 1
- Feature request: add OnTransition callback to Transition class HOT 9
- Name of Test asmdef can conflict with project HOT 1
- StateMachine<T> and StateMachine needs a common StateMachine base type HOT 5
- How to return to the previous sub-state of a Hierarchical FSM? (2.0) HOT 1
- Is there a StateChanged changed event for when any transition occurs, even a sub-machine one? HOT 2
- Trigger/Action should use a separate type
- Documentation request: Explain what HybridStateMachine is
- Sample code can not compile in version 2.0 HOT 2
- Mention Support for Generic State Identifiers Higher Up in README HOT 1
- How to visualize multi-layer state machines HOT 1
- How to use AddTransition in two different TStateId based by enum? HOT 1
- [Question] Any node editor for UnityHfsm?Or other Editor Tool ? HOT 1
- Perform logic in FixedUpdate or LateUpdate?
- More Samples/Explaination On Class-based architecture HOT 1
- How would you model a Weapon StateMachine having a "Idle" Movement and Cooldown in parallel?
- Are there reasons to not use this library outside of Unity? HOT 1
- [Feature Request] States that use tasks instead of Coroutines
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unityhfsm.